#31771 closed Cleanup/optimization (wontfix)
Add warning if model field has trailing comma.
Reported by: | Jonas Haag | Owned by: | nobody |
---|---|---|---|
Component: | Core (System checks) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If someone types (note the trailing comma):
class MyModel(models.Model): trailing_comma = models.IntegerField(),
Django silently ignored the field, possibly leaving you wondering for a very long time what's going on.
I suggest to add a warning to the models checker framework.
If accepted, I'm willing to come up with an initial patch.
Change History (4)
comment:1 by , 4 years ago
Component: | Database layer (models, ORM) → Core (System checks) |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Summary: | Add warning if model field has trailing comma → Add warning if model field has trailing comma. |
UI/UX: | unset |
comment:2 by , 4 years ago
What do you mean by “supported use case”? Obviously defining tuples on model classes generally should not raise a warning, but how about the specific case of tuple of size 1 containing a model field instance?
comment:3 by , 4 years ago
From a quick Google search, this seems to be a common mistake made by a Django beginners.
https://stackoverflow.com/questions/7900162/django-error-with-orm/7900323#7900323
https://stackoverflow.com/questions/26090949/unique-together-refers-to-the-non-existent-field
https://stackoverflow.com/questions/4389367/django-unique-together-does-not-allow-foreignkey-field-across-applications-when
comment:4 by , 4 years ago
It is too specific, we cannot add separate system checks for each kind of typos.
Thanks for this ticket, however we cannot add a system check for tuples defined on models. It's a supported use case.