#11920: Cannot access related field of an unsaved object if the object is from 
an
inherited model
---------------------------------------------------+------------------------
          Reporter:  zbyte64                       |         Owner:  nessita    
               
            Status:  assigned                      |     Milestone:  1.2        
               
         Component:  Database layer (models, ORM)  |       Version:  1.1        
               
        Resolution:                                |      Keywords:  related 
field doesnotexist
             Stage:  Accepted                      |     Has_patch:  0          
               
        Needs_docs:  0                             |   Needs_tests:  0          
               
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by nessita):

 Even though the example is not correct (when creating the {{{new_parent}}}
 object, the old, saved {{{parent}}} instance is used to query the
 {{{baseline_set}}} instead of the unsaved {{{new_parent}}}), the problem
 still persists when doing:

 {{{
 #!python
 In [1]: from fix_11920.models import *

 In [2]: Parent().baseline_set
 Out[2]: <django.db.models.fields.related.RelatedManager object at
 0x96f936c>

 In [3]: Child().sibling_set
 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', (77, 0))

 ---------------------------------------------------------------------------
 DoesNotExist                              Traceback (most recent call
 last)

 /home/nessita/pycon/test_project/<ipython console> in <module>()

 /home/nessita/pycon/django-sprint/lib/python2.6/site-
 packages/django/db/models/fields/related.pyc in __get__(self, instance,
 instance_type)
     352
     353         return self.create_manager(instance,
 --> 354                 self.related.model._default_manager.__class__)
     355
     356     def __set__(self, instance, value):

 /home/nessita/pycon/django-sprint/lib/python2.6/site-
 packages/django/db/models/fields/related.pyc in create_manager(self,
 instance, superclass)
     429         attname = rel_field.rel.get_related_field().name
     430         manager.core_filters = {'%s__%s' % (rel_field.name,
 attname):
 --> 431                 getattr(instance, attname)}
     432         manager.model = self.related.model
     433

 /home/nessita/pycon/django-sprint/lib/python2.6/site-
 packages/django/db/models/fields/related.pyc in __get__(self, instance,
 instance_type)
     262                 if self.field.null:
     263                     return None
 --> 264                 raise self.field.rel.to.DoesNotExist
     265             other_field = self.field.rel.get_related_field()
     266             if other_field.rel:

 DoesNotExist:
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11920#comment:4>
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