Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FBT003: Ignore by default django.db.models.Value #10356

Closed
9128305 opened this issue Mar 12, 2024 · 2 comments · Fixed by #10531
Closed

FBT003: Ignore by default django.db.models.Value #10356

9128305 opened this issue Mar 12, 2024 · 2 comments · Fixed by #10531
Labels
configuration Related to settings and configuration rule Implementing or modifying a lint rule

Comments

@9128305
Copy link

9128305 commented Mar 12, 2024

Hi, there is a common usage of Value(False) | Value(True) in Django projects. Ruff does not provide any configuration to extend the FBT003 default whitelist. So my request would be 1) Ignore Value by default like #6711 2) settings to extend FBT003 whitelist.

from django.db.models import Case, Q, Value, When
...
qs.annotate(
    is_foo_or_bar=Case(
        When(Q(is_foo=True) | Q(is_bar=True)),
        then=Value(True),  # noqa: FBT003
    ),
    default=Value(False),  # noqa: FBT003
)
@zanieb zanieb added rule Implementing or modifying a lint rule configuration Related to settings and configuration labels Mar 12, 2024
@zanieb
Copy link
Member

zanieb commented Mar 12, 2024

An allow-list for this rule does seems reasonable.

@ngnpope
Copy link
Contributor

ngnpope commented Mar 26, 2024

@9128305 It should be possible to use then=True and default=False directly without wrapping with Value(), and that goes for most basic types, not just booleans. The exception is where strings are used, as then="string" would be interpreted as then=F("string"), i.e. a column name, and so then=Value("string") is required explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Related to settings and configuration rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants