Re: [Django] #19064: select_related doesn't work for reverse one-to-one with inheritance

2012-10-03 Thread Django
#19064: select_related doesn't work for reverse one-to-one with inheritance
-+-
 Reporter:  zimnyx   |Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:  duplicate
 Severity:  Normal   | Triage Stage:
 Keywords:   |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by charettes):

 * status:  new => closed
 * resolution:   => duplicate


Comment:

 Marking as duplicate of #13781.

-- 
Ticket URL: 
Django 
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-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Django] #19064: select_related doesn't work for reverse one-to-one with inheritance

2012-10-03 Thread Django
#19064: select_related doesn't work for reverse one-to-one with inheritance
-+-
 Reporter:  zimnyx   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:
 Keywords:   |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by zimnyx):

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


Comment:

 Patch from #13781 fixes this issue.

-- 
Ticket URL: 
Django 
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-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[Django] #19064: select_related doesn't work for reverse one-to-one with inheritance

2012-10-03 Thread Django
#19064: select_related doesn't work for reverse one-to-one with inheritance
--+
 Reporter:  zimnyx|  Owner:  nobody
 Type:  Bug   | Status:  new
Component:  Database layer (models, ORM)  |Version:  master
 Severity:  Normal|   Keywords:
 Triage Stage:  Unreviewed|  Has patch:  0
Easy pickings:  0 |  UI/UX:  0
--+
 == Docs say... ==
 You can also refer to the reverse direction of a !OneToOneField in the
 list of fields passed to select_related — that is, you can traverse a
 !OneToOneField back to the object on which the field is defined. Instead
 of specifying the field name, use the related_name for the field on the
 related object.


 == How to reproduce ==

 {{{
 # myapp/models.py
 class Dam(models.Model):
 name = models.CharField(max_length=32)

 class Animal(models.Model):
 nickname = models.CharField(max_length=32)

 class Beaver(Animal):
 dam = models.OneToOneField(Dam, related_name='beaver')
 favourite_meal = models.CharField(max_length=32)

 }}}


 {{{
 # myapp/fixtures/initial_data.yaml

 - model: myapp.Dam
   pk: 1
   fields:
 name: Hoover

 - model: myapp.Animal
   pk: 1
   fields:
 nickname: Harold

 - model: myapp.Beaver
   pk: 1
   fields:
 dam: 1
 favourite_meal: spagetti

 }}}


 {{{
 # /tmp/mypro$ python2.7 manage.py shell

 In [1]: from mypro.myapp.models import *

 In [2]: Beaver.objects.select_related('dam')
 Out[2]: []

 In [3]: Dam.objects.select_related('beaver')
 Out[3]: []

 In [4]: len(Dam.objects.select_related('beaver'))
 ERROR: An unexpected error occurred while tokenizing input
 The following traceback may be corrupted or invalid
 The error message is: ('EOF in multi-line statement', (494, 0))

 ---
 AttributeErrorTraceback (most recent call
 last)
 /tmp/mypro/django/core/management/commands/shell.pyc in ()
 > 1 len(Dam.objects.select_related('beaver'))

 /tmp/mypro/django/db/models/query.pyc in __len__(self)
  87 self._result_cache = list(self._iter)
  88 else:
 ---> 89 self._result_cache = list(self.iterator())
  90 elif self._iter:
  91 self._result_cache.extend(self._iter)

 /tmp/mypro/django/db/models/query.pyc in iterator(self)
 298 if fill_cache:
 299 obj, _ = get_cached_row(row, index_start, db,
 klass_info,
 --> 300
 offset=len(aggregate_select))
 301 else:
 302 # Omit aggregates in object creation.


 /tmp/mypro/django/db/models/query.pyc in get_cached_row(row, index_start,
 using, klass_info, offset)
1457 for rel_field, rel_model in
 rel_obj._meta.get_fields_with_model():
1458 if rel_model is not None:
 -> 1459 setattr(rel_obj, rel_field.attname,
 getattr(obj, rel_field.attname))
1460 # populate the field cache for any related
 object

1461 # that has already been retrieved


 AttributeError: 'Dam' object has no attribute 'nickname'
 }}}

-- 
Ticket URL: 
Django 
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-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.