Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#10738 closed (fixed)

ContentType and model instances with deferred fields

Reported by: tomasz.elendt Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Suppose we have model like this:

class Entry(models.Model):
    title = models.CharField(max_length=128)
    body = models.TextField()
>>> from blog.models import Entry
>>> # creating new entry object
>>> Entry.objects.create(title="test entry", body="some body content")
>>> entry_1 = Entry.objects.get(title="test entry")
>>> entry_2 = Entry.objects.defer('body').get(title="test entry")
>>> from django.contrib.contenttypes.models import ContentType
>>> ContentType.objects.get_for_model(e1)
<ContentType: entry>
>>> ContentType.objects.get_for_model(e2)
<ContentType: entry_ deferred_body>

ContentTypes for the same model instances with and without deferred fields are not the same (I suppose that's because they're not instances of the same class and have different value). I'm not sure if that's the correct behavior. I mean - does the instance with deferred field(s) should have different ContentType?

I found this issue when i tried use django-tagging and it's template tag tags_for_object with 'deferred QuerySet'. But maybe described behavior is correct and that's django-tagging bug?

Attachments (3)

deferred_model_contenttype.diff (1.2 KB) - added by tomasz.elendt 8 years ago.
deferred_model_contenttype.2.diff (571 bytes) - added by tomasz.elendt 8 years ago.
deferred_model_contenttype_tests.diff (611 bytes) - added by tomasz.elendt 8 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 8 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Version: 1.01.1-beta-1

Changed 8 years ago by tomasz.elendt

comment:2 Changed 8 years ago by tomasz.elendt

Has patch: set
Needs tests: set

Changed 8 years ago by tomasz.elendt

Changed 8 years ago by tomasz.elendt

comment:3 Changed 8 years ago by tomasz.elendt

Needs tests: unset

comment:4 Changed 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

Fixed in r10523.

comment:5 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top