[Django] #27295: An exception on correct code

24 views
Skip to first unread message

Django

unread,
Sep 29, 2016, 10:10:22 AM9/29/16
to django-...@googlegroups.com
#27295: An exception on correct code
-------------------------------+--------------------
Reporter: Victor Porton | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Running `manage.py test` for the attached Django project causes a
meaningless exception.

It is probably because _UsersGroup class name starts with underscore.


{{{
$ python3 manage.py test
Creating test database for alias 'default'...
E
======================================================================
ERROR: test_users (auth_app.tests.UsersGroupTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/porton/Projects/gnosis-error/auth_app/tests.py", line 13, in
setUp
self.A.subgroups.add(self.B)
File "/usr/lib/python3/dist-
packages/django/db/models/fields/related_descriptors.py", line 881, in add
self._add_items(self.source_field_name, self.target_field_name, *objs)
File "/usr/lib/python3/dist-
packages/django/db/models/fields/related_descriptors.py", line 1025, in
_add_items
.values_list(target_field_name, flat=True)
File "/usr/lib/python3/dist-packages/django/db/models/query.py", line
731, in values_list
clone = self._values(*fields)
File "/usr/lib/python3/dist-packages/django/db/models/query.py", line
714, in _values
query.add_fields(field_names, True)
File "/usr/lib/python3/dist-packages/django/db/models/sql/query.py",
line 1630, in add_fields
name.split(LOOKUP_SEP), opts, alias, allow_many=allow_m2m)
File "/usr/lib/python3/dist-packages/django/db/models/sql/query.py",
line 1402, in setup_joins
names, opts, allow_many, fail_on_missing=True)
File "/usr/lib/python3/dist-packages/django/db/models/sql/query.py",
line 1327, in names_to_path
"Choices are: %s" % (name, ", ".join(available)))
django.core.exceptions.FieldError: Cannot resolve keyword 'to' into field.
Choices are: from__usersgroup, from__usersgroup_id, id, to__usersgroup,
to__usersgroup_id

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)
Destroying test database for alias 'default'...
}}}

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

Django

unread,
Sep 29, 2016, 10:10:48 AM9/29/16
to django-...@googlegroups.com
#27295: An exception on correct code
---------------------------+----------------------------

Reporter: Victor Porton | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------+----------------------------
Changes (by Victor Porton):

* Attachment "error.tar.gz" added.

A project which triggers a bug

Django

unread,
Sep 29, 2016, 10:25:44 AM9/29/16
to django-...@googlegroups.com
#27295: Models with underscores break query lookups
-------------------------------------+-------------------------------------

Reporter: Victor Porton | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
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 Tim Graham):

* needs_better_patch: => 0
* needs_docs: => 0
* component: Core (Other) => Database layer (models, ORM)
* needs_tests: => 0


Comment:

My first instinct is to add a system check to prohibit models with
underscores in the name. Maybe we should first ask if anyone is
successfully using such models.

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

Django

unread,
Oct 3, 2016, 12:32:06 PM10/3/16
to django-...@googlegroups.com
#27295: Models with underscores break query lookups
-------------------------------------+-------------------------------------
Reporter: Victor Porton | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
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 Tim Graham):

I [https://groups.google.com/d/topic/django-
developers/ba4x7kKwAfU/discussion posted on django-developers] to ask if
anyone is using underscores in model names.

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

Django

unread,
Oct 3, 2016, 3:43:58 PM10/3/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
--------------------------------------+------------------------------------

Reporter: Victor Porton | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: Bug => Cleanup/optimization
* component: Database layer (models, ORM) => Core (System checks)
* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

The mailing list indicates that underscores are used in model names, so
it's probably enough to prevent underscores at the start of a name.

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

Django

unread,
Oct 4, 2016, 8:24:50 PM10/4/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
--------------------------------------+------------------------------------
Reporter: Victor Porton | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Quentin Fulsher):

If no one minds, I would like to work on this ticket. It seems like this
project would just require adding a system check for the underscore and
then adding tests to check the code is validating the names correctly.

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

Django

unread,
Oct 4, 2016, 8:34:49 PM10/4/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
--------------------------------------+------------------------------------
Reporter: Victor Porton | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham):

Yes, you may claim the ticket, no need to ask.

As Michal suggested on the mailing list, 'I think it makes sense to also
check for and flag as errors model names starting or ending with
underscores, or containing double underscores, since those can lead to
invalid field names."

--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:5>

Django

unread,
Oct 4, 2016, 11:05:07 PM10/4/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
-------------------------------------+-------------------------------------
Reporter: Victor Porton | Owner: Quentin
Type: | Fulsher
Cleanup/optimization | Status: assigned
Component: Core (System | Version: 1.10
checks) |

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Quentin Fulsher):

* owner: nobody => Quentin Fulsher
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:6>

Django

unread,
Oct 11, 2016, 4:08:34 AM10/11/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
-------------------------------------+-------------------------------------
Reporter: Victor Porton | Owner: Quentin
Type: | Fulsher
Cleanup/optimization | Status: assigned
Component: Core (System | Version: 1.10
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Quentin Fulsher):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


Comment:

I submitted a pull request for this ticket here:

https://github.com/django/django/pull/7370

I am having some issues getting the test cases to run correctly. Its
probably just a misunderstanding of how the tests actually work. I go over
it in more detail in the pull request.

--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:7>

Django

unread,
Nov 5, 2016, 11:24:12 AM11/5/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
-------------------------------------+-------------------------------------
Reporter: Victor Porton | Owner: Quentin
Type: | Fulsher
Cleanup/optimization | Status: assigned
Component: Core (System | Version: 1.10
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Federico Capoano):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


Comment:

I improved the patch in pull request
https://github.com/django/django/pull/7500 and paid attention to maintain
the author's original commit.

I believe the patch is good enough to be merged.

--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:8>

Django

unread,
Nov 5, 2016, 12:26:52 PM11/5/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
-------------------------------------+-------------------------------------
Reporter: Victor Porton | Owner: Quentin
Type: | Fulsher
Cleanup/optimization | Status: assigned
Component: Core (System | Version: 1.10
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Federico Capoano):

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:9>

Django

unread,
Nov 16, 2016, 5:34:35 PM11/16/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
-------------------------------------+-------------------------------------
Reporter: Victor Porton | Owner: Quentin
Type: | Fulsher
Cleanup/optimization | Status: assigned
Component: Core (System | Version: 1.10
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:8>

Django

unread,
Nov 22, 2016, 11:28:48 AM11/22/16
to django-...@googlegroups.com
#27295: Add a system check to prohibit models that start with an underscore
-------------------------------------+-------------------------------------
Reporter: Victor Porton | Owner: Quentin
Type: | Fulsher
Cleanup/optimization | Status: closed

Component: Core (System | Version: 1.10
checks) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f62abfc03da61977bf080163f0a2ef014decd86a" f62abfc]:
{{{
#!CommitTicketReference repository=""
revision="f62abfc03da61977bf080163f0a2ef014decd86a"
Fixed #27295 -- Added a system check to prohibit model names that start or
end with an underscore or contain double underscores.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:9>

Reply all
Reply to author
Forward
0 new messages