#11606: return error data  when using only() and select_related() at the same 
times
that models foreign key is set to default null.
---------------------------------------------------+------------------------
          Reporter:  seandong                      |         Owner:  nobody     
              
            Status:  new                           |     Milestone:             
              
         Component:  Database layer (models, ORM)  |       Version:  SVN        
              
        Resolution:                                |      Keywords:  
only,select_related,defer
             Stage:  Accepted                      |     Has_patch:  0          
              
        Needs_docs:  0                             |   Needs_tests:  0          
              
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by brutasse):

 * cc: [email protected] (added)

Comment:

 I have tried to look at this without success. It seems that the generated
 SQL is perfectly fine but some columns get mixed when building the python
 representation.

 I have some models that looks like this:

 {{{
 #!python
 class Category(models.Model):
     color = models.CharField(max_length=50)

 class Feed(models.Model):
     name = models.CharField(max_length=255)
     category = models.ForeignKey(Category, related_name='feeds')

 class Entry(models.Model):
     feed = models.ForeignKey(Feed, related_name='entries')
     title = models.CharField(max_length=255)
     date = models.DateTimeField()
     read = models.BooleanField(default=False, db_index=True)
     user = models.ForeignKey(User, related_name='entries')

 }}}

 If I do:

 {{{
 #!python
 entries = Entry.objects.select_related().only('id', 'feed', 'title',
 'date',
                                               'read', 'feed__name',
                                               'feed__category__color')
 }}}
 then:

 {{{
 #!python
 for e in entries:
     print e.feed.category.color # prints datetime.datetime instances (all
 the same) - related user's creation date
     print e.feed.category.id # prints the related user's password hash
 sha1$cf481$01b13cdfab3.....
 }}}

 So, the problem may not be specific to foreign keys, and the engine
 fetches information from wrong related tables.
 This happens at least on PostgreSQL, I can't confirm on other backends.

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