-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
web.Application and web_urldispatcher.UrlDispatcher can't be used separately #1373
Comments
What's your use case for deriving from |
@asvetlov I don't derive from UrlDispatcher, I just create it explicitly with some factory function. I mean in my case I construct router instance and pass it to application instance, and do not follow pattern used in the docs: app = web.Application()
app.router.add_route(...) Since there's a problem with that pattern either - |
Hmm, but why do you need to create Thus what is your use case? Would you provide a simple code snippet with problem demonstration? |
@asvetlov Who's talking about derivation? :) I'm talking about factory function that somehow gather and return a router that I need to use with my application. Let's say, map endpoints to classes from YAML or create various router classes based on some parameter in the config. To me it sounds like a valid case especially taking into account that Regarding my particular case. I've decided to use router as a way to do API versioning. In my case I have |
I closed my ticket #1365, but I think I'll join in on this. It would be nice to be able to instantiate UrlDispatchers separately, or rely on that behavior. For my project (aiohttp-transmute), my job becomes a lot easier if I can rely on a dispatcher that handles basic mounting of routes resolving to the appropriate path. I guess if UrlDispatcher isn't supposed to be extended (or public), I would just continue to build my tooling around it's methods anyway, since that's the default router and I'm going to guess that a lot of people will have a painful upgrade if the default router behavior changed. Just some thoughts. Maybe you can say that you're not supposed to extend from it, but it's pretty "public" already. |
actually |
@asvetlov ^^^ |
+1 on this. The thing is, |
@fafhrd91 From my perspective |
I'm having the same issue that I am overwriting My use case for this is adding route-based validation of incoming request using JSON schema. Being able to subclass If subclassing |
Since aiohttp 1.1 some backward incompatible changes have been implemented. Despite each of them has its own issue on GitHub: - aio-libs/aiohttp#1373 - aio-libs/aiohttp#1416 it's not clear when they become resolved. In order to be able to fly on latest aiohttp version, this commit resolves those issues by implementing workarounds on our side.
Fixed by #1458 |
That's awesome! Thanks a lot! |
UrlDispatcher does not depend on Application anymore |
Long story short
Since aiohttp 1.1.0 there's no correct way to create
web.Application
andweb_urldispatcher.UrlDispatcher
separately, since the latest requires the former as argument and both saves each other as protected properties.possible solutions is to patch protected property:
aiohttp users can't rely on protected attributes, since they may changed from version to version.
Expected behaviour
There should be a proper way to resolve this solution.
Actual behaviour
Workaround is needed.
Steps to reproduce
web_urldispatcher.UrlDispatcher
independently and pass it toweb.Application
.Your environment
The text was updated successfully, but these errors were encountered: