-
-
Notifications
You must be signed in to change notification settings - Fork 41
Description
Thank you for this amazing library! I’ve been using it for the past couple of months.
Currently, the SQLAlchemy backend does not allow extra attributes beyond those defined in the SQLAlchemy model. It would be beneficial to add support for additional filter parameters. For example:
class NoteFilterParams(Filter):
date__gte: OptionalParam[date] = None
date__lte: OptionalParam[date] = None
class Constants(Filter.Constants):
model = Note
NoteFilter = Annotated[NoteFilterParams, FilterDepends(NoteFilterParams)]
@router.get("/notes")
def fetch_notes(note_filter: NoteFilter):
func(note_filter)In this example, if we want to add custom filtering logic, we would typically add a custom filter parameter to NoteFilterParams. However, this approach throws an AttributeError. We can work around this by adding additional query parameters to the router:
@router.get("/notes")
def fetch_notes(note_filter: NoteFilter, extra_query: Annotated[str, Query()]):
func(note_filter, extra_query)Unfortunately, this leads to redundancy when we want to apply the same filtering logic across different routes, such as /teams/{team_id}/notes and /groups/{group_id}/notes. This results in further code duplication as the number of custom filter parameters increases. Additionally, the OpenAPI documentation generated by FastAPI does not support multiple query parameter classes, preventing us from grouping custom filter parameters effectively.
If you believe this feature would be valuable, I would be happy to implement it.