Skip to content

Commit

Permalink
Fix for unicode PK
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaxxl committed Aug 22, 2024
1 parent d68e82f commit 8889ff9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions safrs/jsonapi_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ def jsonapi_sort(object_query, safrs_object):
if sort_attr == "id":
if attr is None:
if safrs_object.id_type.primary_keys:
attr = getattr(safrs_object, safrs_object.id_type.primary_keys[0]) # todo: composite keys edge case
sort_attr = attr.name
attr = getattr(safrs_object, safrs_object.id_type.primary_keys[0], None) # todo: composite keys edge case
if attr is not None: # might be the case if pk is unicode
sort_attr = attr.name
else:
continue
elif attr is None or sort_attr not in safrs_object._s_jsonapi_attrs:
Expand Down
6 changes: 5 additions & 1 deletion safrs/safrs_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def get_id(cls, obj):
values = [str(getattr(obj, pk.name)) for pk in cls.columns]
return cls.delimiter.join(values)

return getattr(obj, cls.primary_keys[0])
pk = getattr(obj, cls.primary_keys[0], None)
if pk is None:
pks = [ c.name for c in cls.columns[0].table.columns if c.primary_key ]
return cls.delimiter.join(pks)
return pk

@classmethod
def get_pks(cls, jsonapi_id):
Expand Down

0 comments on commit 8889ff9

Please sign in to comment.