-
-
Couldn't load subscription status.
- Fork 516
Description
When trying to upgrade to django-stubs 5.0.3 or 5.0.4 in Zulip, I get 25 unexpected errors like error: "type[RealmFilter]" has no attribute "objects" [attr-defined]. This is not #1684; RealmFilter is a normal concrete model class. The issue seems to depend on the structure of the project’s import graph.
Based on git bisect, it first occurs at
I’ve reduced the issue to this minimized test case: https://github.com/andersk/no-attribute-objects
$ mypy .
zerver/models/__init__.py:6: error: "type[RealmFilter]" has no attribute "objects" [attr-defined]
Found 1 error in 1 file (checked 10 source files)pyproject.toml
[tool.django-stubs]
django_settings_module = "zproject.settings"
[tool.mypy]
plugins = ["mypy_django_plugin.main"]confirmation/__init__.py (empty)
confirmation/models.py
from django.db import models
from zerver.models import Realm
class Confirmation(models.Model):
realm = models.ForeignKey(Realm, on_delete=models.RESTRICT)zerver/__init__.py (empty)
zerver/models/__init__.py
from zerver.models.linkifiers import RealmFilter as RealmFilter
from zerver.models.realms import Realm as Realm
from zerver.models.streams import Stream as Stream
from zerver.models.users import UserProfile as UserProfile
RealmFilter.objectszerver/models/linkifiers.py
from django.db import models
class RealmFilter(models.Model):
passzerver/models/realms.py
from django.db import models
class Realm(models.Model):
passzerver/models/streams.py
from django.db import models
from zerver.models.realms import Realm
from zerver.models.users import UserProfile
class Stream(models.Model):
realm = models.ForeignKey(Realm, on_delete=models.RESTRICT)
creator = models.ForeignKey(UserProfile, on_delete=models.RESTRICT)zerver/models/users.py
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
class UserProfile(AbstractBaseUser, PermissionsMixin):
passzproject/__init__.py (empty)
zproject/settings.py
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"confirmation",
"zerver",
]