-
-
Notifications
You must be signed in to change notification settings - Fork 450
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
Skip executing apps.ready
for installed apps
#1341
base: master
Are you sure you want to change the base?
Conversation
Ah sorry. Seems like a good idea, although not a fan of the monkeypatching. What gave me pause is that I imagine some people might be using the |
If this is purely from the If the ready callbacks are only necessary for e.g.
IMO this is a major design issue with the current plugin design -- importing checked code into the mypy runtime is problematic for many reasons (also mentioned in #1337 (comment)). This PR only fixes a symptom of that, but the list of issues reported with this symptom is impressive for sure. Ideally we should also think about what a better design would look like. Although such a solution would probably take a lot longer. |
Just as the real goal of the plugin should be to not have to boot django's runtime, I don't think there should be any reason the plugin should support some arbitrary runtime code to be executed. I wouldn't claim that as a reason not to monkey patch ourselves, if we'd benefit from it.
The timing isn't important and it has nothing to do with django or django-stubs. It was specifics for that project is all.
I think
While all that might be true, I think it'd help out skipping What I'm trying to say is; that I'm thinking patching |
Are you opposed to making this configurable? You've demonstrated the issues solved by this change well. But it could open some other can of worms that causes issues for a different set of users.
Yep, that's the thing. Django itself always unconditionally calls these hooks and we have no idea what users may be doing in those. We do initialize Django within the mypy process; this change would make a Django project in mypy context behave differently from a usual Django runtime context. Then we expect to be able to introspect models and settings in this different runtime context. We could hypothesize that no user does anything in these ready() hooks that affects the introspection behavior, but I'm afraid Hyrum's Law will prove us wrong. If some poor soul does hit this issue, it would be better if we can reply "OK just disable this option" than "welp, just keep using the old django-stubs version then". The latter has been our de facto stance in #1276 for example. |
Not really, no. But if so I'd prefer enabling the monkey patch of |
Yes agreed about defaulting to enabled. |
@flaeppe Are you planning to revive this? I hope I haven't discouraged you. :) |
Sure, I just haven't gotten around to it. |
I have made things!
I got an idea from reading #1337 (comment), that it'd be possible and also preferable to avoid triggering
AppConfig.ready
forINSTALLED_APPS
. For multiple reasons:django-stubs
crashing for reasons unrelated todjango-stubs
(https://github.com/typeddjango/django-stubs/issues?q=is%3Aissue+%22in+ready%22).AppConfig.ready
. It should work without it.django-stubs
shorterThe approach taken here is quite invasive(i.e. monkey patching with
unittest.mock
), it could be done in multiple ways. Consider it a PoC.Related issues
Closes #1312