-
-
Notifications
You must be signed in to change notification settings - Fork 456
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
bug/regression in 4.2.4: Model typed through Generics has no attribute "objects" #1686
Comments
Duplicate of #1684 |
I actually read that documentation before posting this and while it may not be your fault or documentation, this is very confusing. Why would this be ok from django.db.models import Model
class CoolClass(Model):
pass
CoolClass.objects.count() and not this from django.db.models import Model
M = TypeVar("M", bound=Model)
Type[M].objects.count() # Not exactly like this, but you get my point You are using exactly the same type information Should |
Maybe i need to read up on the god forsaken TypeVar definition again -.- |
from django.db.models import Model
class CoolClass(Model):
pass
CoolClass.objects.count()
The important difference compared to T = TypeVar("T", bound=models.Model) Is that we set an upper bound to the parent class of all models here. I can very well have done what you see below, to my class MyCoolModel(models.Model):
not_objects = models.Manager()
print(type(MyCoolModel.not_objects))
try:
MyCoolModel.objects
except AttributeError:
print("Oh no") The key thing to take away here is that when we're talking about the base class |
Thank you for this explanation, its kinda bad design by django, but at least i understand it, and django-stubs certainly are behaving correct. Thank you again. |
I can open a new issue if it’s more relevant, but I feel the 2nd use case was a bit overlooked, but is a real issue:
The last line of the paragraph in Django’s doc about Am I missing something? |
I don't see where it clearly states so? I see this though
So, that means it behaves just regularly regarding default/first declared managers I think? Perhaps there's an improvement if we sort out that there's no explicit Anyway, we still have #1549 to fix first. So if |
I read:
So it assumes But yeah, fixing #1549 is probably the proper plan. |
Ok, I re-read your answer. I actually agree with what your saying (re: implicit vs explicit |
Bug report
After upgrading from 4.2.3 -> 4.2.4 I am seeing different problems with typing related to [Model].objects in my codebase. Lazily i have only recreated one of the cases in minimalist example.
What's wrong
Case 1 - Model typed through Generics ++
->
Case 2 - ManyToMany objects ref
->
How is that should be
No mypy errors. Works with 4.2.3.
System information
python
version: 3.11.3django
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: