#2316: GenericRelation and get_or_create do not work together -------------------------------------+-------------------------------------- Reporter: Rudolph | Owner: adrian Status: reopened | Milestone: Component: Core framework | Version: 1.1 Resolution: | Keywords: GenericRelation Stage: Accepted | Has_patch: 1 Needs_docs: 0 | Needs_tests: 1 Needs_better_patch: 0 | -------------------------------------+-------------------------------------- Changes (by wam):
* status: closed => reopened * version: SVN => 1.1 * resolution: duplicate => Comment: This bug is neither a duplicate nor has it been fixed. Using Django 1.1.1, the issue still persists, as demonstrated by: {{{ # Model definition for app ticket2316 demonstrating bug #2316 from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class SomeObject(models.Model): test_content_type = models.ForeignKey(ContentType, null=True, blank=True) test_object_id = models.PositiveIntegerField(null=True, blank=True) test_object = generic.GenericForeignKey('test_content_type', 'test_object_id') }}} After the customary syncdb, etc: {{{ >>> from ticket2316.models import SomeObject >>> from django.contrib.auth.models import User >>> User.objects.all()[0] <User: wam> >>> user = _ >>> SomeObject(test_object=user) <SomeObject: SomeObject object> >>> SomeObject.objects.get_or_create(test_object=user) ------------------------------------------------------------ Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/wam/projs/virtualenvs/demo/lib/python2.6/site- packages/Django-1.1.1-py2.6.egg/django/db/models/manager.py", line 123, in get_or_create return self.get_query_set().get_or_create(**kwargs) File "/home/wam/projs/virtualenvs/demo/lib/python2.6/site- packages/Django-1.1.1-py2.6.egg/django/db/models/query.py", line 328, in get_or_create return self.get(**kwargs), False File "/home/wam/projs/virtualenvs/demo/lib/python2.6/site- packages/Django-1.1.1-py2.6.egg/django/db/models/query.py", line 299, in get clone = self.filter(*args, **kwargs) File "/home/wam/projs/virtualenvs/demo/lib/python2.6/site- packages/Django-1.1.1-py2.6.egg/django/db/models/query.py", line 498, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/home/wam/projs/virtualenvs/demo/lib/python2.6/site- packages/Django-1.1.1-py2.6.egg/django/db/models/query.py", line 516, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/home/wam/projs/virtualenvs/demo/lib/python2.6/site- packages/Django-1.1.1-py2.6.egg/django/db/models/sql/query.py", line 1675, in add_q can_reuse=used_aliases) File "/home/wam/projs/virtualenvs/demo/lib/python2.6/site- packages/Django-1.1.1-py2.6.egg/django/db/models/sql/query.py", line 1569, in add_filter negate=negate, process_extras=process_extras) File "/home/wam/projs/virtualenvs/demo/lib/python2.6/site- packages/Django-1.1.1-py2.6.egg/django/db/models/sql/query.py", line 1737, in setup_joins "Choices are: %s" % (name, ", ".join(names))) <class 'django.core.exceptions.FieldError'>: Cannot resolve keyword 'test_object' into field. Choices are: id, test_content_type, test_object_id }}} I'll try and work up a more formal unittest in the near future. P.S. I don't exactly know how I should change the properties, considering this ticket has remained dormant for the past two years. I considered filing a new ticket, but the problem is *exactly* the failure condition this ticket was originally opened to address, it just appears the ticket got diverted onto a tangent with a similar, but not identical ticket that the original poster may have been experiencing as well. -- Ticket URL: <http://code.djangoproject.com/ticket/2316#comment:7> Django <http://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 post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.