Flask-Middleware / flask-security

Quick and simple security for Flask applications
MIT License
622 stars 154 forks source link

Getting type hints for csrf_cookie_handler results in "NameError: name 'Response' is not defined" #966

Closed KonradCichocki7 closed 2 months ago

KonradCichocki7 commented 3 months ago

I want to use the flask security together with an injector (a dependency injection framework for python). But when I enable csrf all requests fail. After some digging I found out that injector tries to scan any method that is going to be invoked during the request handling (in this case csrf_cookie_handler) to see if it needs to inject anything.

Since csrf_cookie_handler is not annotated with any @inject annotations it should happily ignore it, but it fails on finding type hints for this function. Fixing it should be a matter of taking the import statement for the Response out of the if statement. Gonna submit a PR in a moment

jwag956 commented 2 months ago

I have no problem changing that one - I have that in a work area - however this does seem to be an issue with injector - there is nothing I can tell that requires or suggests that all annotations have to be imported at run time.