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

log a warning or error when adding something to blueprint after adding it to application #2255

Closed
fredlllll opened this issue Oct 2, 2021 · 6 comments · Fixed by #2260
Closed
Assignees

Comments

@fredlllll
Copy link
Contributor

Is your feature request related to a problem? Please describe.
when i add a blueprint to the sanic app, and then add routes to it, those routes dont work. i have to add the blueprint to the app after adding routes. but there is no indication that im doing something wrong if i do it the wrong way

Describe the solution you'd like
log a warning or error message telling the programmer that they added routes to a blueprint after adding it to the app, and that those routes will not work. or straight up throw an error

@ahopkins
Copy link
Member

ahopkins commented Oct 2, 2021

💯

This should be the case for any Blueprint addition (routes, listeners, middleware, exception handlers, signals).

@prryplatypus
Copy link
Member

I might give this one a try tomorrow or on Monday

@Tronic
Copy link
Member

Tronic commented Oct 3, 2021

Or better yet, make the blueprint changes work even after added to an app, if doing so is feasible.

@ahopkins
Copy link
Member

ahopkins commented Oct 3, 2021

Or better yet, make the blueprint changes work even after added to an app, if doing so is feasible.

This could be a bit messy, and I believe would require a bit of a refactor from how the decorators work. I think it also breaks the principle of what the Blueprint is, but perhaps could be doable with something like this:

    def route(self, *args, **kwargs):
        kwargs["apply"] = False
        sup = super().route

        def wrapper(handler):
            retval = sup(*args, **kwargs)(handler)
            for app in self.apps:
                self.register(app, {})
            return retval

        return wrapper

If we are going this direction, then we need to definitely beef up the unit testing around this, and probably make all of these methods (route, static, middleware, exception, signal) perhaps a little more DRY.

@ahopkins
Copy link
Member

ahopkins commented Oct 3, 2021

@prryplatypus I am going to take this one myself. I hope you do not mind.

@prryplatypus
Copy link
Member

All good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants