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

Inspect middleware parameters before passing in lifespan #1686

Merged
merged 2 commits into from
Apr 22, 2023

Conversation

RobbeSneyders
Copy link
Member

Fixes #1682

This PR inspects the parameters of a Middleware class before passing in the lifespan keyword argument. I was doubting to check the class instead (isinstance(LifespanMiddleware)), but that's less flexible if users want to write custom middleware to handle the lifespan.

@RobbeSneyders RobbeSneyders added this to the Connexion 3.0 milestone Apr 13, 2023
Copy link
Member

@Ruwann Ruwann left a comment

Choose a reason for hiding this comment

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

LGTM. I agree that this approach looks more extensible than checking the class.

@@ -233,7 +234,11 @@ def _build_middleware_stack(self) -> t.Tuple[ASGIApp, t.Iterable[ASGIApp]]:
app = self.app
apps = [app]
for middleware in reversed(self.middlewares):
app = middleware(app, lifespan=self.lifespan) # type: ignore
arguments, has_kwargs = inspect_function_arguments(middleware)
Copy link
Member

Choose a reason for hiding this comment

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

nit: unused variable has_kwargs

Base automatically changed from feature/add-middleware to main April 22, 2023 19:37
@coveralls
Copy link

coveralls commented Apr 22, 2023

Pull Request Test Coverage Report for Build 4774427774

  • 17 of 17 (100.0%) changed or added relevant lines in 8 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 93.631%

Totals Coverage Status
Change from base Build 4774418228: 0.007%
Covered Lines: 3337
Relevant Lines: 3564

💛 - Coveralls

@RobbeSneyders RobbeSneyders merged commit 1beb053 into main Apr 22, 2023
5 checks passed
@RobbeSneyders RobbeSneyders deleted the bugfix/middleware-init-kwargs branch April 22, 2023 20:01
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.

Connexion 3.0.0a4, GZIP Middleware
3 participants