Opened 11 years ago
Closed 11 years ago
#22050 closed Bug (fixed)
defer('related__subfield') and select_related() on proxy model raises error
Reported by: | lovasb | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.6 |
Severity: | Normal | Keywords: | defer, proxy, query |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Given model (in the defer test directory):
class Secondary(models.Model): first = models.CharField(max_length=50) second = models.CharField(max_length=50) @python_2_unicode_compatible class Primary(models.Model): name = models.CharField(max_length=50) value = models.CharField(max_length=50) related = models.ForeignKey(Secondary) def __str__(self): return self.name class PrimaryProxy(Primary): class Meta: proxy = True
Select only() on related models: PrimaryProxy.objects.all().select_related().only('related__first')
Raises KeyError:
E ====================================================================== ERROR: test_defer_proxy_related_field (defer.tests.DeferTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/lovasb/WORK/Personal/django/tests/defer/tests.py", line 176, in test_defer_proxy_related_field self.assertEqual(len(children), 1) File "/home/lovasb/WORK/Personal/django/django/db/models/query.py", line 122, in __len__ self._fetch_all() File "/home/lovasb/WORK/Personal/django/django/db/models/query.py", line 963, in _fetch_all self._result_cache = list(self.iterator()) File "/home/lovasb/WORK/Personal/django/django/db/models/query.py", line 222, in iterator only_load = self.query.get_loaded_field_names() File "/home/lovasb/WORK/Personal/django/django/db/models/sql/query.py", line 1819, in get_loaded_field_names self.deferred_to_data(collection, self.get_loaded_field_names_cb) File "/home/lovasb/WORK/Personal/django/django/db/models/sql/query.py", line 602, in deferred_to_data must_include[old_model].add(source) KeyError: <class 'defer.models.PrimaryProxy'>
Attachments (3)
Change History (10)
by , 11 years ago
Attachment: | defer_models.py added |
---|
follow-up: 3 comment:1 by , 11 years ago
Hi,
Could you submit a pull request for this, or at least consolidate all the patches into one? It would make reviewing the ticket easier.
Thanks.
follow-up: 4 comment:2 by , 11 years ago
Looks like there's one already: https://github.com/django/django/pull/2279
comment:3 by , 11 years ago
Replying to bmispelon:
Hi,
Could you submit a pull request for this, or at least consolidate all the patches into one? It would make reviewing the ticket easier.
Thanks.
Hi,
Here is my pull request: https://github.com/django/django/pull/2279/files
Bence
comment:4 by , 11 years ago
Replying to bmispelon:
Looks like there's one already: https://github.com/django/django/pull/2279
Yeah, that's mine! :)
comment:5 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:6 by , 11 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|
comment:7 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Defer test models.py