Skip to content

Cannot filter with None on _id attributes of FK/OneToOne #3472

Description

@UnknownPlatypus

Bug report

The validation of allowed filters seem to be incorrect for the _id variant of Fk/OneToOne fields

What's wrong

class MyModel(models.Model):
    prospect = models.OneToOneField(
        "foo.OtherModel"
        blank=True,
        null=True,
        on_delete=models.CASCADE,
    )

MyModel.objects.filter(prospect=None) # OK
MyModel.objects.filter(prospect_id=None) # error: Incompatible type for lookup 'prospect_id': (got "None", expected "str | int")  [misc]

How is that should be

MyModel.objects.filter(prospect=None) # OK
MyModel.objects.filter(prospect_id=None) # OK

System information

  • OS: ubuntu 24.04
  • python version: 3.11
  • django version: 5.2.15
  • mypy version: 2.1.0
  • django-stubs version: 6.0.6
  • django-stubs-ext version: 6.0.6

Activity

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

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