Skip to content

Commit

Permalink
Fix csv lookup for 'id'
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaxxl committed Nov 28, 2023
1 parent a9c759c commit cffef30
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions safrs/jsonapi_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from flask import request
from sqlalchemy.orm import joinedload, Query



def create_query(cls):
"""
Create a query for the target collection `cls`.
Expand Down Expand Up @@ -78,8 +76,11 @@ def jsonapi_filter(cls) -> Query:

for attr_name, val in filters.items():
if attr_name == "id":
return cls._s_get_instance_by_id(val)
if attr_name not in cls._s_jsonapi_attrs:
attr = getattr(cls,'id',None)
if attr is None:
# todo: add support for composite pkeys using `cls.id_type.get_pks`
return cls._s_get_instance_by_id(val)
elif attr_name not in cls._s_jsonapi_attrs:
# validation failed: this attribute can't be queried
safrs.log.warning(f"Invalid filter {attr_name}")
return []
Expand Down

0 comments on commit cffef30

Please sign in to comment.