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

[ENHANCEMENT]: DJ001 avoid using null=True on string-based fields such as CharField #23

Open
hairmare opened this issue Apr 17, 2024 · 1 comment
Labels
backend This issue or pull request is backend related enhancement This issue or pull request discusses non feature changes quality This issue or pull request is quality related

Comments

@hairmare
Copy link
Contributor

hairmare commented Apr 17, 2024

DJ001:

Warning

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

It would require a migration (if the null=True) gets dropped and might break something (don't know for sure tho)

Originally posted by @c0rydoras in adfinis/timed-backend#1049 (comment)

@hairmare
Copy link
Contributor Author

Lets take the discussion on this rule here... In adfinis/timed-backend#1049 (comment) @winged posits that this is just dogmatically trying to satisfy the linter. The ruleset on the other hands tells us

If a string-based field is nullable, then your model will have two possible representations for "no data": None and the empty string. This can lead to confusion, as clients of the API have to check for both None and the empty string when trying to determine if the field has data.

The Django convention is to use the empty string in lieu of None for string-based fields.

In our case we could have a look at some client code to see if both forms are checked (given it's what the rule wants to prevent) or it might even be that the issue isn't exposed and the confusion is reverted during serialization.

@c0rydoras c0rydoras transferred this issue from adfinis/timed-backend May 13, 2024
@c0rydoras c0rydoras added enhancement This issue or pull request discusses non feature changes backend This issue or pull request is backend related quality This issue or pull request is quality related labels May 13, 2024
@c0rydoras c0rydoras changed the title DJ001 Avoid using null=True on string-based fields such as CharField [ENHANCEMENT]: DJ001 avoid using null=True on string-based fields such as CharField Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend This issue or pull request is backend related enhancement This issue or pull request discusses non feature changes quality This issue or pull request is quality related
Projects
None yet
Development

No branches or pull requests

2 participants