Skip to content

[attr-defined] error on one-to-one relation #2609

Open
@yoanis-sl

Description

@yoanis-sl

Bug report

What's wrong

I have the following models:

# Content from video.models

class BackingVideo(AudioMixin):
    asset = models.OneToOneField(
        "video.Asset", on_delete=models.SET_NULL, null=True, blank=True, related_name="backing_video"
    )
class Asset(BaseModelMixin):
    mux_asset_id = models.CharField(max_length=512, blank=False)

and when I run mypy on the code base I get this error:

video/management/commands/copy_mux_assets.py:126: error: "Asset" has no attribute "backing_video"  [attr-defined]
Found 1 error in 1 file (checked 75 source files)

Which seems a bit strange as I seem to have all of the proper setup.

This is what the relevant pyproject.toml file looks like:

[tool.mypy]
explicit_package_bases = true
plugins = ["mypy_django_plugin.main", "mypy_drf_plugin.main"]
ignore_missing_imports = false
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true

[tool.django-stubs]
django_settings_module = "config.settings"

Any thoughts on what I might be doing wrong here?

Any help is appreciated. Thx!

System information

  • OS:
  • python version: 3.13
  • django version: 5.1.7
  • mypy version: 1.15.0
  • django-stubs version: 5.1.3
  • django-stubs-ext version: 5.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions