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.
* Attachment "error.tar.gz" added.
A project which triggers a bug
* 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>
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>
* 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>
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>
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>
* owner: nobody => Quentin Fulsher
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:6>
* 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>
* 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>
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:9>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27295#comment:8>
* 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>