Skip to content

Mypy can't get custom manager type #1067

Open
@maximsht

Description

@maximsht

I have custom user model that inherits from UserProfile from django-tenant-users package. UserProfile has custom model manager. In my model I see an error from mypy:
Mypy: Could not resolve manager type for "Flow_BE.applications.users.models.User.objects"
and when i try to use this manager I receive error:
Mypy: "Manager[User]" has no attribute "create_user"

This is how models specified:

class User(UserProfile):
    """This User model replaces default user model."""

# from django-tenant-users
class UserProfile(AbstractBaseUser, PermissionsMixinFacade):

    objects = UserProfileManager()

class UserProfileManager(BaseUserManager):

    def create_user(
            self,
            email=None,
            password=None,
            is_staff=False,
            **extra_fields,
        ):...

For User.objects.create_user(...) mypy generates errors. Code works.

System information

  • OS: MacOs 12.3.1
  • python version: 3.10.4
  • django version: 4.0.6
  • mypy version: 0.971
  • django-stubs version: 1.12.0
  • django-stubs-ext version: 0.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    3rd partyPresence of a third party dependency has been mentionedbugSomething isn't workingmypy-pluginIssues specific to mypy_django_plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions