-
-
Notifications
You must be signed in to change notification settings - Fork 480
Fix missing related managers on some models #902
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
Fix missing related managers on some models #902
Conversation
I was seeing an issue where some related managers were missing from some models. Traced the issue down to this line, where it appears that if we hit a relation with a non-default(?) reverse manager the iteration stopped. I _think_ this is supposed to be a continue statement instead. It appears to work in the project I'm working in at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Can you please create a unit test for this?
I'll try, but I'm honestly not entirely sure how to reproduce it. It just happened on a few of our models, but I don't see anything special about them. Will give it a try though :) |
@sobolevn As far as I can tell this is related to the Basically it appears to me that the branch where it's returning is supposed to short-circuit the logic that ends up generating the type info and store it here: But as it's returning, not continuing the loop, it's not short-circuiting just that one field, but all remaining fields on the model. I see that we hit the same branch for Any chance we could get this out without a test case? Alternatively any pointers to where I can start looking to get a reproducer? |
Finally managed to reproduce it. Don't ask my why it's failing or what's going on, but this test case fails without the fix and works with the fix. |
reveal_type(Model1().test2) # N: Revealed type is "app3.models.Model4_RelatedManager" | ||
reveal_type(Model2().test2) # N: Revealed type is "app3.models.Model4_RelatedManager" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the fix these attributes will be missing, as it returns after adding the .test
attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I think I can explain somewhat. Reverse managers should be created on the fly (dynamically if you will) to avoid one having to annotate them, i.e. This is a long sentence but, essentially, with the So, I think, the "return bug" would appear if a model has > 1 reverse relations. e.g. I don't know if this "explanation" helps at all, just thought I might try to clarify. |
Thanks for the explanation, it makes it a bit clearer at least!
This isn't entirely true, as it was working on some of our models with > 1 reverse relation, but not all, so there's something else as well that has to be in place to trigger the bug. Anyway, should be fixed now, the hardest part here was reproducing it 😅 |
True, processing order of the reverse relations might be involved here too, i.e. in which order relations are iterated over (since it'll return on the first one having declared a default manager for reverse relations) Anyways, nice catch and that you figured out a repro 👍 |
I'm bumping into this but I don't think it's released in 1.10.0 -- are there any plans to release 1.10.1 soon? |
Bumping as this is not available in release 1.10.1. Would be included in a future 1.10.2 release, any chance for that soon? |
I still have most related managers missing after the latest upgrades to the type checker code. The patch we used to have to apply to an older version of django-mypy was this one: HyreAS@2ec7384. But i'm not quite sure as to how i would apply this to the current state of the code. Some related managers do get set up, so it seems like django-mypy just gives up at a certain point and stops adding more related managers. Our models are on the form
I'll try to create a repro, but haven't had any luck making a reduced test case actually fail on ci before. |
This is a dump of what i get with some extra logging added:
When adding logging here: Unsure where to go from here. |
I was seeing an issue where some related managers were missing from some
models. Traced the issue down to this line, where it appears that if we
hit a relation with a non-default(?) reverse manager the iteration
stopped. I think this is supposed to be a continue statement instead.
It appears to work in the project I'm working in at least.