Skip to content

Mark abstract auth and session models as abstract - #427

Merged
kodiakhq[bot] merged 1 commit into
sbdchd:mainfrom
kalekseev:abstract-auth-models-meta
Oct 29, 2026
Merged

kodiakhq[bot] merged 1 commit into
sbdchd:mainfrom
kalekseev:abstract-auth-models-meta

Conversation

@kalekseev

Copy link
Copy Markdown

AbstractBaseUser, PermissionsMixin, AbstractUser and AbstractBaseSession are abstract at runtime, but the stubs don't say so. AbstractBaseSession declares abstract: ClassVar[bool] with no value, and the other three have no Meta.

ty 0.0.93 has Django primary key support and adds an automatic id: int to every model it doesn't know is abstract. A user model with a UUID primary key on another base then gets id: int, plus invalid-attribute-override errors on id:

class UUIDModel(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4)

    class Meta:
        abstract = True


class User(AbstractBaseUser, PermissionsMixin, UUIDModel): ...


reveal_type(User().id)  # int before, UUID after
  • Add class Meta with abstract: ClassVar[bool] = True to AbstractBaseUser, PermissionsMixin and AbstractUser, and give AbstractBaseSession.Meta.abstract the value True. ty only treats a model as abstract when abstract has the value True; an annotation alone doesn't count.
  • AbstractUser.Meta subclasses both parent Meta classes so that pyright doesn't report an incompatible override.

There is no test because CI pins ty 0.0.82, which has no Django primary key support. I checked the change with ty 0.0.93 against an installed copy of the stubs. ruff, mypy, pyright and pytest results are the same as on main.

@kalekseev

Copy link
Copy Markdown
Author

@sharkdp WDYT? WIth astral-sh/ruff#29744 we have to add Meta.abstract = True to stubs.

@kodiakhq
kodiakhq Bot merged commit af8df47 into sbdchd:main Oct 29, 2026
2 checks passed
@sharkdp

sharkdp commented Nov 2, 2026

Copy link
Copy Markdown

@kalekseev Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants