#21410: Error when trying to ignore reverse relationships with related_name using the "+" ----------------------------------------------+--------------------------- Reporter: troygrosfield | Owner: nobody Type: Bug | Status: new Component: Database layer (models, ORM) | Version: 1.6 Severity: Normal | Keywords: related_name, Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+--------------------------- The setup and failing test can be seen below. It's trying to use the related name as an actual field. I didn't see this issue until I just upgraded to django 1.6 yesterday. Am I missing something here?
{{{ # models.py from django.db import models from django.contrib.auth.models import User class ModelA(models.Model): created_user = models.ForeignKey( User, related_name='%(app_label)s_%(class)s_created_user+') last_modified_user = models.ForeignKey( User, related_name='%(app_label)s_%(class)s_last_modified_user+') }}} {{{ # tests.py from tests.models import ModelA from django.contrib.auth.models import User class Django16PrefetchBug(TestCase): def test_prefetch_bug(self): u1 = User.objects.get_or_create(username='hello1', email='he...@world.com', password='hi')[0] u2 = User.objects.get_or_create(username='hello2', email='he...@world.com', password='hi')[0] u3 = User.objects.get_or_create(username='hello3', email='he...@world.com', password='hi')[0] m1 = ModelA.objects.create(created_user=u1, last_modified_user=u2) m2 = ModelA.objects.create(created_user=u2, last_modified_user=u3) m3 = ModelA.objects.create(created_user=u3, last_modified_user=u2) x = ModelA.objects.all().prefetch_related('created_user') # The line below fails when evaluating the query. y = list(x) }}} {{{ ====================================================================== ERROR: test_prefetch_bug (tests.prefetch_bug.Django16PrefetchBug) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/troy/github/django-recurrence/tests/prefetch_bug.py", line 249, in test_prefetch_bug y = list(x) File "/path/to/site-packages/django/db/models/query.py", line 96, in __iter__ self._fetch_all() File "/path/to/site-packages/django/db/models/query.py", line 856, in _fetch_all self._prefetch_related_objects() File "/path/to/site-packages/django/db/models/query.py", line 517, in _prefetch_related_objects prefetch_related_objects(self._result_cache, self._prefetch_related_lookups) File "/path/to/site-packages/django/db/models/query.py", line 1598, in prefetch_related_objects obj_list, additional_prl = prefetch_one_level(obj_list, prefetcher, attr) File "/path/to/site-packages/django/db/models/query.py", line 1697, in prefetch_one_level prefetcher.get_prefetch_queryset(instances) File "/path/to/site-packages/django/db/models/fields/related.py", line 277, in get_prefetch_queryset qs = self.get_queryset(instance=instances[0]).filter(**query) File "/path/to/site-packages/django/db/models/query.py", line 590, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/path/to/site-packages/django/db/models/query.py", line 608, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/path/to/site-packages/django/db/models/sql/query.py", line 1198, in add_q clause = self._add_q(where_part, used_aliases) File "/path/to/site-packages/django/db/models/sql/query.py", line 1232, in _add_q current_negated=current_negated) File "/path/to/site-packages/django/db/models/sql/query.py", line 1100, in build_filter allow_explicit_fk=True) File "/path/to/site-packages/django/db/models/sql/query.py", line 1351, in setup_joins names, opts, allow_many, allow_explicit_fk) File "/path/to/site-packages/django/db/models/sql/query.py", line 1274, in names_to_path "Choices are: %s" % (name, ", ".join(available))) FieldError: Cannot resolve keyword u'tests_modela_created_user+' into field. Choices are: date_joined, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, password, user_permissions, username }}} -- Ticket URL: <https://code.djangoproject.com/ticket/21410> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/056.1acea90b050957938b43448c166b93ed%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.