Skip to content

Feature request : warning when incorrectly using __isnull filters #3033

@malo-malo

Description

@malo-malo

Bug report

What's wrong

This is more of a feature request (for which I did not find a template).
I would like to have a warning or an error when incorrectly using __isnull filters on a field that cannot be null.

How is that should be

For example, with the following model

class MyModel(models.Model):
  name = models.CharField(null=False)

I would like to have warnings in the following cases :

MyModel.objects.filter(name__isnull=False) # Always true, this is a noop that should be removed
MyModel.objects.filter(name__isnull=True) # Filters out the entire queryset, probably a mistake

System information

  • OS: Ubuntu 22.04.5 LTS
  • python version: Python 3.11.14
  • django version: 4.2.26
  • mypy version: 1.16.1
  • django-stubs version: 5.2.1
  • django-stubs-ext version: 5.2.1

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