#22047 closed Bug (fixed)
Cannot resolve keyword u'group_ptr' into field. Choices are: group, id, name, permissions, user
Reported by: | Chris Chan | Owned by: | Konrad Świat |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I recently tried to upgrade from 1.5.1 to 1.6.2 and am now getting this error for inherited many to many relationships.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/manager.py", line 133, in all
return self.get_queryset()
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/fields/related.py", line 549, in get_queryset
return super(ManyRelatedManager, self).get_queryset().using(db)._next_is_sticky().filter(self.core_filters)
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/query.py", line 590, in filter
return self._filter_or_exclude(False, *args, kwargs)
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/query.py", line 608, in _filter_or_exclude
clone.query.add_q(Q(*args, kwargs))
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1198, in add_q
clause = self._add_q(where_part, used_aliases)
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1234, in _add_q
current_negated=current_negated)
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1100, in build_filter
allow_explicit_fk=True)
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1357, in setup_joins
names, opts, allow_many, allow_explicit_fk)
File "/opt/bg/common/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1277, in names_to_path
"Choices are: %s" % (name, ", ".join(available)))
django.core.exceptions.FieldError: Cannot resolve keyword u'group_ptr' into field. Choices are: group, id, name, permissions, user
Change History (9)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
This error will happen when you try to navigate through the users' django.db.models.fields.related.ManyRelatedManager
g = Group.objects.get(id=89)
g.users.all()
comment:3 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 11 years ago
I slimmed down the models a bit:
from django.db import models from django.contrib.auth.models import User as DjangoUser, Group as DjangoGroup class User(DjangoUser): pass class Group(DjangoGroup): users = models.ManyToManyField(User, through='Membership', related_name='groups') class Membership(models.Model): user = models.ForeignKey(User) group = models.ForeignKey(Group)
The problem seems to be the related_name='groups'
parameter. If you remove it, things work.
I'm not fully convinced that this is a bug because having groups
as a related_name
actually clashes with the groups
field on User
.
comment:5 by , 11 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
https://docs.djangoproject.com/en/dev/topics/db/models/#fields mentions that one should not create fields which clash with the API. You create a field which clashes with the API. Ergo, it doesn't work.
comment:6 by , 11 years ago
Has patch: | set |
---|---|
Resolution: | invalid |
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
@AeroNotix, you're right, but the clash should be detected by system check framework. I and mondone have written a patch: https://github.com/django/django/pull/2289.
comment:7 by , 11 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:9 by , 11 years ago
Thanks for discovering the real issue, I'll ensure there are no field and related name clashes, the error didnt help much in seeing that issue.
My model looks like so.
import json, logging, hashlib, random, time, base64, sys, urlparse
from django.contrib.auth.models import User as DjangoUser, Group as DjangoGroup, GroupManager as DjangoGroupManager
class GroupManager(DjangoGroupManager):
class Group(DjangoGroup):
def generateSalt():
class User(DjangoUser):
class Membership(models.Model):