Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Allow Additional Filter Parameters When Using SQLAlchemy Backend #600

Open
enkhjilnt opened this issue Oct 3, 2024 · 1 comment

Comments

@enkhjilnt
Copy link

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.

Copy link

github-actions bot commented Dec 8, 2024

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Dec 8, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 14, 2024
@arthurio arthurio reopened this Dec 14, 2024
@github-actions github-actions bot removed the Stale label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants