astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.19k stars 1.07k forks source link

[flake8-django] DJ001 is not raised for fields which has unique=True #13887

Open kiddten opened 2 days ago

kiddten commented 2 days ago
class Product(models.Model):
    test = models.CharField(null=True, blank=True, max_length=255)

is correct

DJ001 Avoid using null=True on string-based fields such as CharField

but

class Product(models.Model):
    test = models.CharField(null=True, blank=True, max_length=255, unique=True)

All checks passed!

gives no warning

ruff version 0.7.0

kiddten commented 2 days ago

Hmm looks like this is expected behaviour https://github.com/astral-sh/ruff/blob/4d109514d608b45bc11a5ecf3e022112461cb571/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs#L105

UnknownPlatypus commented 2 days ago

See https://docs.djangoproject.com/en/5.1/ref/models/fields/#null for the rationale. This is indeed expected behavior