Your message dated Tue, 26 Sep 2017 17:22:10 +0000
with message-id <e1dwtyg-0002ej...@fasolo.debian.org>
and subject line Bug#876816: fixed in python-django 1:1.11.5-2
has caused the Debian Bug report #876816,
regarding python-django: Can't defer() fields from super- and sub-class at the 
same time
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact ow...@bugs.debian.org
immediately.)


-- 
876816: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=876816
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
--- Begin Message ---
Package: python-django
Severity: normal
Tags: patch

Upstream bug: https://code.djangoproject.com/ticket/28549

From the upstream bug report:

-----------------------------
 Using the models:

from django.db import models

class Base(models.Model):
    f1 = models.CharField(max_length=10)

class Sub(Base):
    f2 = models.CharField(max_length=10)

it seems that I can't defer() both f1 and f2 in a single query:

Sub.objects.defer('f1', 'f2').query.sql_with_params()[0]
u'SELECT "defer_base"."id", "defer_base"."f1", "defer_sub"."base_ptr_id" FROM "defer_sub" INNER JOIN "defer_base" ON ("defer_sub"."base_ptr_id" = "defer_base"."id")'

(we're seeing f1 in the SELECT value list).

I seem to be able to defer f1 or f2 separately though.

I'm no django hacker, but: it seems as though django.db.models.sql.query.Query.deferred_to_data() is iterating both models in the loop:

#640:
            for model, values in six.iteritems(seen):
                for field in model._meta.fields:
                    if field in values:
                        continue

- and so is discovering f1 twice: once as Base.f1 and again as Sub.f1. Since the field in values test only skips Base.f1, we're still left with Sub.f1 in the workset dict.
-----------------------------

This bug caused significant performance degradation when we upgraded a Django application to a new version that relied on model inheritance.

The attached patch is a backport of commit 84b7cb7df00192b2f804e2c6fd98b78b5bfd1ffa from upstream master.

This issue applies to both 1:1.10.7-2 and 1:1.11.5-1.

Patch supplied by Jeremy Kerr and tested/backported by Daniel Axtens.


Regards,
--
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnel...@au1.ibm.com  IBM Australia Limited
>From ac607f20c2dbcd2cfd88fcd8b78259d75abdb7d4 Mon Sep 17 00:00:00 2001
From: Jeremy Kerr <j...@ozlabs.org>
Date: Thu, 31 Aug 2017 08:59:45 +0800
Subject: [PATCH] Fixed #28549 -- Fixed QuerySet.defer() with super and
 subclass fields.

commit 84b7cb7df00192b2f804e2c6fd98b78b5bfd1ffa upstream.

Previously, deferring fields in different classes didn't omit the
superclass' deferred field.

Thanks Simon Charette for the suggested fix.

[ajd: backported on top of Debian tree]
Signed-off-by: Andrew Donnellan <andrew.donnel...@au1.ibm.com>
---
 django/db/models/sql/query.py | 2 +-
 tests/defer/tests.py          | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index e51b1037c..8813dce57 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -669,7 +669,7 @@ class Query(object):
             # models.
             workset = {}
             for model, values in six.iteritems(seen):
-                for field in model._meta.fields:
+                for field in model._meta.local_fields:
                     if field in values:
                         continue
                     m = field.model._meta.concrete_model
diff --git a/tests/defer/tests.py b/tests/defer/tests.py
index 65f1f2bb1..ef7180a85 100644
--- a/tests/defer/tests.py
+++ b/tests/defer/tests.py
@@ -190,6 +190,11 @@ class BigChildDeferTests(AssertionMixin, TestCase):
         self.assertEqual(obj.value, "foo")
         self.assertEqual(obj.other, "bar")
 
+    def test_defer_subclass_both(self):
+        # Deferring fields from both superclass and subclass works.
+        obj = BigChild.objects.defer("other", "value").get(name="b1")
+        self.assert_delayed(obj, 2)
+
     def test_only_baseclass_when_subclass_has_added_field(self):
         # You can retrieve a single field on a baseclass
         obj = BigChild.objects.only("name").get(name="b1")
-- 
2.11.0


--- End Message ---
--- Begin Message ---
Source: python-django
Source-Version: 1:1.11.5-2

We believe that the bug you reported is fixed in the latest version of
python-django, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 876...@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Chris Lamb <la...@debian.org> (supplier of updated python-django package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmas...@ftp-master.debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Tue, 26 Sep 2017 17:51:23 +0100
Source: python-django
Binary: python-django python-django-common python-django-doc python3-django
Built-For-Profiles: nocheck
Architecture: source all
Version: 1:1.11.5-2
Distribution: unstable
Urgency: medium
Maintainer: Debian Python Modules Team 
<python-modules-team@lists.alioth.debian.org>
Changed-By: Chris Lamb <la...@debian.org>
Description:
 python-django - High-level Python web development framework (Python 2 version)
 python-django-common - High-level Python web development framework (common)
 python-django-doc - High-level Python web development framework (documentation)
 python3-django - High-level Python web development framework (Python 3 version)
Closes: 876816
Changes:
 python-django (1:1.11.5-2) unstable; urgency=medium
 .
   * Fix QuerySet.defer() with super and subclass fields. (Closes: #876816)
   * Use --abbrev=7 when using git pq export.
Checksums-Sha1:
 17f17eafb0edbd47eca0dd5398737b9765478a72 3176 python-django_1.11.5-2.dsc
 ed2a7c654a386c2ac0fb2a87a929ba1290b0cdf1 23292 
python-django_1.11.5-2.debian.tar.xz
 579b50c13255adf1a8dbbfabdb8b4abc7b4be3dd 1543038 
python-django-common_1.11.5-2_all.deb
 c1b6a8494ce7d6265687ae4cc3667ea6060fd702 2598724 
python-django-doc_1.11.5-2_all.deb
 832e92b0335cc9528b26c8361904a2830ed3a8cc 914744 python-django_1.11.5-2_all.deb
 5a4656da3311bf595044b22ed6d89e832237b005 8157 
python-django_1.11.5-2_amd64.buildinfo
 82e84b8e4ac00b76245ddbc3937006c733421360 914716 python3-django_1.11.5-2_all.deb
Checksums-Sha256:
 d3efbb8f928f08f7cd275f5fc3255042cee31b5836b2fd9e52b7e4f23958b688 3176 
python-django_1.11.5-2.dsc
 97679d1f50bc08317f1ee899804b15861233f4521155af8046f60b0ebbd7fbd4 23292 
python-django_1.11.5-2.debian.tar.xz
 d6b6576608a0a2dcdd6ee4a90435a16ade5eb7af45a8901b717ed84da37d73a3 1543038 
python-django-common_1.11.5-2_all.deb
 e385aa77c774266de61d1ea27f99a973bd96dcd49f47d8685b0a3acb4806ae06 2598724 
python-django-doc_1.11.5-2_all.deb
 e0bb6550dc2497d675ac902a6ba098ec47ee98a08cc36161f70af2ea07253a5f 914744 
python-django_1.11.5-2_all.deb
 8fe93ab8b7fb9ca7f55d6342ba1b138bdf09210eed0c577764fca56cca6d8ae3 8157 
python-django_1.11.5-2_amd64.buildinfo
 14576ca6881c50c3560aeb801bc0ffb248c68f0aa9d4cd76507cd643ce8187ff 914716 
python3-django_1.11.5-2_all.deb
Files:
 54c84f5e155e317be46cb80f62b4c88d 3176 python optional 
python-django_1.11.5-2.dsc
 02b651aee21857a5787e3aece6e3e241 23292 python optional 
python-django_1.11.5-2.debian.tar.xz
 79134b862c336fe2b0356d3a555f0c3e 1543038 python optional 
python-django-common_1.11.5-2_all.deb
 ff151afcc3ec5bd40dafc736a7d9f2d3 2598724 doc optional 
python-django-doc_1.11.5-2_all.deb
 7746e133a41d3d09d8170a2a6646ec26 914744 python optional 
python-django_1.11.5-2_all.deb
 d0bf0204a602291ea250d56131c4bdb8 8157 python optional 
python-django_1.11.5-2_amd64.buildinfo
 587a1c580e004f03eeee9f2a03b99483 914716 python optional 
python3-django_1.11.5-2_all.deb

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEwv5L0nHBObhsUz5GHpU+J9QxHlgFAlnKhrUACgkQHpU+J9Qx
HliD+Q/9GQKuDBjkG5z1oitfsfdn/bu2bzv+ZFi+z6S6j2AlGEhbYWRlCEmTcMld
e+xTxx5xkpxe/wsA7xJr5KtjBu/KZssDhZqnzlUvBe7GaGWJSq0H26GkmWACslBU
87bpUA5i3HRHPzebQnfh3yPUeCDJP66jRsehC5VQtV221H4C6MoDEoCU7TS3dHEi
AIR0kgAMvOKq8MPWn+kSXGYIrtkaSi/Z3mrd1jVL4BViAA/8eZ4Nm2IAAHp6xNBd
PEhYnTtHVJSxVrPzcjv5qWbJe2ENnNhGWjclt/gLoLYesruSEmEgJ0xfpvI2XtGo
rhHVX8VdvzAEurPvYag93rCLGkCyKW8H9aRL0HZfFzcqUKzYxoLajj0mRwSjTvNK
ZBcmNkHmfzyRy9MvvtEGARfwNwSMUOhkWiLvoABpeOJ87U4a40wOcPGu3Erefblu
+qYI7syflz0wJkFSJ3mZ/BEvrK3fK7+S9j3ZIbRQn0bCTyKQ4AipBCYu8ICQS6NK
5cQEpvj6b1KJxj34AKV16B0zqNRHXSlkcj6Y0ZBzv/5WBWDIwNxQD1iRSLzYmIrI
JkWRT60OS38fgvw7kzkVgQuckjoIeMwCpmUIf5ZkOTXq9gp69EiGy+QJh3uzpU5/
fD4QBfWT1SmGhUO3xncv/plk2rqqQXFoeuL41RkPNVTQ2MQTHJ4=
=Av1g
-----END PGP SIGNATURE-----

--- End Message ---
_______________________________________________
Python-modules-team mailing list
Python-modules-team@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/python-modules-team

Reply via email to