Skip to content

Be more lenient with route arguments in AuthencationMiddleware 'requires' decorator#942

Merged
erewok merged 2 commits intoKludex:masterfrom
hanneskuettner:fix/decorated-route-with-requires
Aug 16, 2020
Merged

Be more lenient with route arguments in AuthencationMiddleware 'requires' decorator#942
erewok merged 2 commits intoKludex:masterfrom
hanneskuettner:fix/decorated-route-with-requires

Conversation

@hanneskuettner
Copy link
Contributor

As mentioned in #794 (comment) the @requires decorator is too strict as to where it expects arguments to be. It always expects there to be at least one non-keyword argument that is the request.

With a custom decorator (that is similar to the dependency injection in FastAPI) this assumption breaks. Looking at the code it looks like the @requires decorator already supports getting the request from the keyword arguments but still expects there to be a non-empty args list.

So I added back the default value of None in case there are no args passed to the route call. It will still fail at runtime if no request parameter is given.

I also added tests to the test suite that cover all three cases.

@hanneskuettner hanneskuettner force-pushed the fix/decorated-route-with-requires branch from 69fe740 to 4e39caf Compare May 12, 2020 15:47
Copy link

@v0y v0y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice MR with very nice tests, pls merge asap

@hanneskuettner
Copy link
Contributor Author

@erewok Any chance there will be a release in the near future that incorporates this fix?

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

Successfully merging this pull request may close these issues.

4 participants