-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
Model.objects cannot be defined using QuerySet.as_manager #1713
Comments
We've been using django-stubs for more than a year, and that's the hardest upgrade we had so far, TBH. Automatic inference of |
I've noted the problem of inheritance with a base that has managers and such too. I've started working out some stuff on it here: #1699 However, noting the type you have on your base's manager; Since django-stubs/django-stubs/db/models/base.pyi Lines 21 to 23 in dd60767
Also note that I think this should allow you to avoid having to declare the |
To clarify I meant to remove any |
Thank you, I'll give it a try on Monday and report back here. |
I think now I get what you mean. So, I solved the problem by removing the objects declaration from the base model and copy-pasting it into every submodel. Before: class BasePromotion(models.Model):
objects = PromotionQuerySet.as_manager()
class Promotion(BasePromotion):
pass
class SubscriptionPromotion(BasePromotion):
objects = SubscriptionPromotionQuerySet.as_manager() After: class BasePromotion(models.Model):
pass
class Promotion(BasePromotion):
objects = PromotionQuerySet.as_manager()
class SubscriptionPromotion(BasePromotion):
objects = SubscriptionPromotionQuerySet.as_manager() It's not perfect, especially if there are lots of submodels, but should do for now. |
Bug report
What's wrong
How is that should be
The second error was there before but the first one is newly introduced in 4.2.4. As suggested in #1712 (comment), this code should be explicitly annotated. However, the problem is that if I annotate it like this:
Then all custom attributes defined in the SubscriptionPromotionQuerySet won't be available in
SubscriptionPromotion.objects
.In other words, before django-stubs-ext used to construct on the fly the return type of
QuerySet.as_manager
as a mix of Manager and custom methods but now I can't use it because I have to add explicit annotations, and there is no explicit annotation for this dynamically constructed type.System information
python
version:3.8
django
version: 4.2.4mypy
version: 1.5.1django-stubs
version: 4.2.4django-stubs-ext
version: 4.2.2The text was updated successfully, but these errors were encountered: