Skip to content

Does not work with django-auto-prefetch models and fields #1467

@yatharth

Description

@yatharth

Bug report

What's wrong

django-stubs fails to work with models using django-auto-prefetch.

If I have a class like this:

import 

class Bar(auto_prefetch.Model):
   bar = CharField(max_length=10)

class Foo(auto_prefetch.Model):
    foo = auto_prefetch.ForeignKey(
        Bar, on_delete=models.PROTECT
    )

and then I try to typecheck this code

def hello(foo: Foo):
    print(foo.bar)

I get errors like this:

[...].py:[...]: error: "Model" has no attribute "bar"

How is that should be

Whatever django-stubs is doing to make regular models and ForeignKeys work should also work with models that are inheriting from auto_prefetch.Model.

System information

  • OS: macOS 13.1
  • python version: 3.11
  • django version: 3.2.18
  • mypy version: 0.961
  • django-stubs version: 1.12.0
  • django-stubs-ext version: 0.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmypy-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