[Django] #31771: Add warning if model field has trailing comma

4 views
Skip to first unread message

Django

unread,
Jul 7, 2020, 1:42:25 PM7/7/20
to django-...@googlegroups.com
#31771: Add warning if model field has trailing comma
-------------------------------------+-------------------------------------
Reporter: Jonas | Owner: nobody
Haag |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/31771>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 7, 2020, 2:41:01 PM7/7/20
to django-...@googlegroups.com
#31771: Add warning if model field has trailing comma.
-------------------------------------+-------------------------------------
Reporter: Jonas Haag | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => wontfix
* ui_ux: 1 => 0
* component: Database layer (models, ORM) => Core (System checks)


Comment:

Thanks for this ticket, however we cannot add a system check for tuples
defined on models. It's a supported use case.

--
Ticket URL: <https://code.djangoproject.com/ticket/31771#comment:1>

Django

unread,
Jul 7, 2020, 4:43:44 PM7/7/20
to django-...@googlegroups.com
#31771: Add warning if model field has trailing comma.
-------------------------------------+-------------------------------------
Reporter: Jonas Haag | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jonas Haag):

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/31771#comment:2>

Django

unread,
Jul 7, 2020, 4:53:42 PM7/7/20
to django-...@googlegroups.com
#31771: Add warning if model field has trailing comma.
-------------------------------------+-------------------------------------
Reporter: Jonas Haag | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jonas Haag):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/31771#comment:3>

Django

unread,
Jul 7, 2020, 4:58:37 PM7/7/20
to django-...@googlegroups.com
#31771: Add warning if model field has trailing comma.
-------------------------------------+-------------------------------------
Reporter: Jonas Haag | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

It is too specific, we cannot add separate system checks for each kind of
typos.

--
Ticket URL: <https://code.djangoproject.com/ticket/31771#comment:4>

Reply all
Reply to author
Forward
0 new messages