Skip to content
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

"type[Model]" has no attribute "objects" error #1754

Closed
jewelvadim opened this issue Oct 4, 2023 · 1 comment
Closed

"type[Model]" has no attribute "objects" error #1754

jewelvadim opened this issue Oct 4, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jewelvadim
Copy link

Bug report

Mypy error in function

from contextlib import suppress
from typing import Type

from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Model


def get_next_pk(model: Type[Model]) -> int:
    pk = 1
    with suppress(ObjectDoesNotExist):
        pk = model.objects.latest('pk').pk + 1

    return pk

mypy.ini

[mypy]
python_version = 3.11
plugins = mypy_django_plugin.main, mypy_drf_plugin.main
exclude = .git, .idea, .mypy_cache, .ruff_cache, node_modules
cache_dir = ./.cache/mypy
check_untyped_defs = true
disallow_untyped_decorators = true
disallow_untyped_calls = true
ignore_errors = false
ignore_missing_imports = true
implicit_reexport = false
local_partial_types = true
no_implicit_optional = true
strict_optional = true
strict_equality = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unreachable = true
warn_no_return = true

[mypy.plugins.django-stubs]
django_settings_module = 'settings'

What's wrong

After run mypy . I receive next error:

apps/core/functions/get_next_pk.py:11: error: "type[Model]" has no attribute "objects"  [attr-defined]

System information

  • OS: Ubuntu 22.04
  • python version: 3.11
  • django version: 4.2.5
  • mypy version: 1.5.1
  • django-stubs version: 4.2.4
  • django-stubs-ext version: 4.2.2
@jewelvadim jewelvadim added the bug Something isn't working label Oct 4, 2023
@flaeppe
Copy link
Member

flaeppe commented Oct 4, 2023

Duplicate of #1684

@flaeppe flaeppe marked this as a duplicate of #1684 Oct 4, 2023
@flaeppe flaeppe closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants