#13741: GenericForeignKey not working across multiple databases
-----------------------------------+----------------------------------------
          Reporter:  bartek        |         Owner:  nobody                     
  
            Status:  new           |     Milestone:                             
  
         Component:  Contrib apps  |       Version:  1.2                        
  
        Resolution:                |      Keywords:  
contenttype,genericforeignkey
             Stage:  Unreviewed    |     Has_patch:  0                          
  
        Needs_docs:  0             |   Needs_tests:  0                          
  
Needs_better_patch:  0             |  
-----------------------------------+----------------------------------------
Changes (by kmtracey):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Old description:

> It seems that you can't use a GenericForeignKey across multiple
> databases. My model is as follows:
>
> class Item(Model):
>     content_type = models.ForeignKey(ContentType)
>     object_id = models.PositiveIntegerField()
>     content_object = generic.GenericForeignKey()
>     # Other model fields, irrelevant to this example.
>
> From my tests, the following two scenarios happen:
>
> Scenario 1: I use the content_object approach, which uses the actual
> GenericForeignKey field to handle the data.
>
> # Accessory is from a secondary database. I use routers to select it from
> the second database.
> >>> a = Accessory.objects.get(pk=3)
> >>> a
> <Accessory: 1019 - Blue>
> >>> i = Item(content_object=a, title="Test item")
> >>> i.save()
> >>> item = Item.objects.get(pk=1)
> >>> item.content_object
> <ATotallyDifferentModel: some_other_value>
> >>> item.object_id
> 3L # This is correct
>
> So it looks like it doesn't pick the right table to work with. It picks
> another model from the primary database, not going for the second
> database.
>
> Scenario 2: I don't use content_object and set the id/type manually.
>
> >>> ctype = ContentType.objects.get_for_model(Accessory)
> >>> fi = Item.objects.create(object_id=a.pk, content_type=ctype,
> title="Some real item.")
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "/home/bartek/.virtualenvs/internal/lib/python2.6/site-
> packages/django/db/models/manager.py", line 138, in create
>     return self.get_query_set().create(**kwargs)
>   File "/home/bartek/.virtualenvs/internal/lib/python2.6/site-
> packages/django/db/models/query.py", line 352, in create
>     obj.save(force_insert=True, using=self.db)
> TypeError: save() got an unexpected keyword argument 'using'
>
> So at this point I am at a loss. I asked around and no one knows if this
> is a bug or if I'm doing something wrong, so I am assuming it's a bug.

New description:

 It seems that you can't use a !GenericForeignKey across multiple
 databases. My model is as follows:
 {{{
 class Item(Model):
     content_type = models.ForeignKey(ContentType)
     object_id = models.PositiveIntegerField()
     content_object = generic.GenericForeignKey()
     # Other model fields, irrelevant to this example.
 }}}
 From my tests, the following two scenarios happen:

 Scenario 1: I use the content_object approach, which uses the actual
 !GenericForeignKey field to handle the data.

 # Accessory is from a secondary database. I use routers to select it from
 the second database.
 {{{
 >>> a = Accessory.objects.get(pk=3)
 >>> a
 <Accessory: 1019 - Blue>
 >>> i = Item(content_object=a, title="Test item")
 >>> i.save()
 >>> item = Item.objects.get(pk=1)
 >>> item.content_object
 <ATotallyDifferentModel: some_other_value>
 >>> item.object_id
 3L # This is correct
 }}}
 So it looks like it doesn't pick the right table to work with. It picks
 another model from the primary database, not going for the second
 database.

 Scenario 2: I don't use content_object and set the id/type manually.
 {{{
 >>> ctype = ContentType.objects.get_for_model(Accessory)
 >>> fi = Item.objects.create(object_id=a.pk, content_type=ctype,
 title="Some real item.")
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/home/bartek/.virtualenvs/internal/lib/python2.6/site-
 packages/django/db/models/manager.py", line 138, in create
     return self.get_query_set().create(**kwargs)
   File "/home/bartek/.virtualenvs/internal/lib/python2.6/site-
 packages/django/db/models/query.py", line 352, in create
     obj.save(force_insert=True, using=self.db)
 TypeError: save() got an unexpected keyword argument 'using'
 }}}
 So at this point I am at a loss. I asked around and no one knows if this
 is a bug or if I'm doing something wrong, so I am assuming it's a bug.

Comment:

 Fixed description formatting. PLEASE use WikiFormatting and preview before
 submitting.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13741#comment:1>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to