Code

Opened 5 years ago

Closed 4 years ago

#11844 closed (duplicate)

Select_related() and defer()

Reported by: krylatij Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords: selected_related,defer
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Invalid field values when you use select_related() and defer().
See sample below.
May be it clashes with ticket #11606

#models.py

class Author(models.Model):
    name = models.CharField(max_length=20, default='author')
    text1 = models.CharField(default='text1', max_length=10)
    text2 = models.CharField(default='text2', max_length=10)
    
    def __unicode__(self):
        return u'%s' % self.name
     
class Work(models.Model):
    name = models.CharField(max_length=20, default='work')
    author = models.ForeignKey(Author)   
    
    def __unicode__(self):
        return u'%s' % self.name

#manage.py shell

from test.myapp.models import *
a = Author()
a.save()
w = Work()
w.author = a
w.save()
w = Work.objects.filter(id=1).select_related('author').defer('author__text1')[0]
print w.author.text1
>> u'text2'  !!! ERROR

Attachments (0)

Change History (2)

comment:1 Changed 5 years ago by drdaeman

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Possibly, the same bug as in #10733?

comment:2 Changed 4 years ago by russellm

  • Resolution set to duplicate
  • Status changed from new to closed

Closing as a duplicate of #11606, as the reporter suggested.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.