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
There are no similar issues or pull requests for this yet.
Is your feature related to a problem? Please describe.
In my application, I have started using FastAPI Custom Routes to log requests and responses and add transactional headers. However, I can't use the new route class for the SQLAdmin routes because I cannot set the route class.
Describe the solution you would like.
The ability to pass route_class as an argument to the Admin.__init__() method would be a nice way to fix this issue.
I have experimented with this and I have found that while it "works" for the most part, it causes an issue with the login_required decorator.
def login_required(func: Callable[..., Any]) -> Callable[..., Any]:
"""Decorator to check authentication of Admin routes.
If no authentication backend is setup, this will do nothing.
"""
@functools.wraps(func)
async def wrapper_decorator(*args: Any, **kwargs: Any) -> Any:
admin, request = args[0], args[1]
auth_backend = admin.authentication_backend
if auth_backend is not None:
response = await auth_backend.authenticate(request)
if response and isinstance(response, Response):
return response
return await func(*args, **kwargs)
return wrapper_decorator
The decorator expects two args but when using subclasses of fastapi.APIRoute, the request argument is passed as a kwarg instead.
Describe alternatives you considered
I previously used custom middleware to achieve this. I am trying to move away from it because it caused a few issues with asynchronous execution of Background Tasks. For now, I have kept the middleware just on the SQLAdmin router. This allows me to still use background tasks elsewhere and keep logs of SQLAdmin calls. I do have to support two logging mechanisms, which isn't ideal.
Additional context
No response
The text was updated successfully, but these errors were encountered:
I think adding a check to get it from args or kwargs, and see if it solves the integration with the rest of the code.
Feel free to create a PR and contribute to this.
hmvp
linked a pull request
Dec 10, 2024
that will
close
this issue
Checklist
Is your feature related to a problem? Please describe.
In my application, I have started using FastAPI Custom Routes to log requests and responses and add transactional headers. However, I can't use the new route class for the SQLAdmin routes because I cannot set the route class.
Describe the solution you would like.
The ability to pass
route_class
as an argument to theAdmin.__init__()
method would be a nice way to fix this issue.I have experimented with this and I have found that while it "works" for the most part, it causes an issue with the
login_required
decorator.The decorator expects two
args
but when using subclasses offastapi.APIRoute
, therequest
argument is passed as akwarg
instead.Describe alternatives you considered
I previously used custom middleware to achieve this. I am trying to move away from it because it caused a few issues with asynchronous execution of Background Tasks. For now, I have kept the middleware just on the SQLAdmin router. This allows me to still use background tasks elsewhere and keep logs of SQLAdmin calls. I do have to support two logging mechanisms, which isn't ideal.
Additional context
No response
The text was updated successfully, but these errors were encountered: