#33816: QuerySet.only() after select_related() crash on proxy models.
-------------------------------------+-------------------------------------
     Reporter:  Ipakeev              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * stage:  Unreviewed => Accepted


Comment:

 Thanks for the report. Would you like to prepare a patch? A regression
 test is required, e.g.
 {{{#!diff
 diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py
 index f2f465678b..2081c0cbe3 100644
 --- a/tests/proxy_models/tests.py
 +++ b/tests/proxy_models/tests.py
 @@ -390,6 +390,12 @@ class ProxyModelTests(TestCase):
              repr(resp), "<ProxyImprovement: ProxyImprovement:improve
 that>"
          )

 +    def test_select_related_only(self):
 +        user = ProxyTrackerUser.objects.create(name="Joe Doe",
 status="test")
 +        issue = Issue.objects.create(summary="New issue", assignee=user)
 +        qs =
 Issue.objects.select_related("assignee").only("assignee__status")
 +        self.assertEqual(qs.get(), issue)
 +
      def test_proxy_load_from_fixture(self):
          management.call_command("loaddata", "mypeople.json", verbosity=0)
          p = MyPerson.objects.get(pk=100)
 }}}

 > If I replace it by
 > `opts = cur_model._meta.concrete_model._meta`
 > all works as expected.
 I would fix `cur_model` instead:
 {{{
 cur_model = cur_model._meta.concrete_model
 opts = cur_model._meta
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33816#comment:1>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070181b83d03ae-4ff6978f-5d1d-4a09-8b2f-a14e89b1c21c-000000%40eu-central-1.amazonses.com.

Reply via email to