You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a situation where I want to fetch all products based on the currently selected category. However, if there is no category selected, the query will look something like:
localhost:8000/products?category_id=
This is my product filter:
class ProductFilter(Filter): category_id: Optional[uuid.UUID] = None
The problem is, this will throw a validation error because the type given is not a uuid but rather an empty string. If I try to change the type to string, it will later error on the SQL side. The behavior I'm expecting is for all products to be filtered resulting in an empty response.
In SQL it is possible to do something like IS NULL but I don't see a way of doing this with fastapi-filter.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a situation where I want to fetch all products based on the currently selected category. However, if there is no category selected, the query will look something like:
localhost:8000/products?category_id=
This is my product filter:
class ProductFilter(Filter): category_id: Optional[uuid.UUID] = None
The problem is, this will throw a validation error because the type given is not a uuid but rather an empty string. If I try to change the type to string, it will later error on the SQL side. The behavior I'm expecting is for all products to be filtered resulting in an empty response.
In SQL it is possible to do something like IS NULL but I don't see a way of doing this with fastapi-filter.
Anyone have any ideas how to tackle this?
Beta Was this translation helpful? Give feedback.
All reactions