[Django] #33273: queryset.update SQL does not receive fields from base model of inheriting model.

1 view
Skip to first unread message

Django

unread,
Nov 9, 2021, 8:39:03 AM11/9/21
to django-...@googlegroups.com
#33273: queryset.update SQL does not receive fields from base model of inheriting
model.
-----------------------------------------+------------------------
Reporter: James Miller | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
In an admin function, I receive a queryset with the class that was
registered with the admin decorator, @admin.register(ForumComment), where
the queryset is populated with ForumComments selected to approve, where
they have been reported for moderation.

In my approve_comment function, I use queryset.update(moderation=None).
The ForumComment model extends from a Comment model in another app. When
the code 'queryset.update(moderation=None) runs I get the following error:
```
*** django.db.utils.OperationalError: (1054, "Unknown column
'django_posts_and_comments_comment.date_created' in 'order clause'"
```
It seems that the queryset.update method is unable to scope the model
'ForumComment' to correctly include the methods/properties of the
superclass 'Comment'.

I have just returned to the code base after a while away, and I think that
it worked, and the error is new. I have solved the error by iterating
over the records of the queryset and saving each one individually using
update_fields for efficiency, but the queryset.update should work.

I have asked this question at the forum where I have included code etc.
https://forum.djangoproject.com/t/unknown-field-in-order-clause-when-
using-model-inheritance/10444/2

In sum, should it not be the case that queryset.update is capable of
generating SQL that will correctly include the fields of a superclass
model?

--
Ticket URL: <https://code.djangoproject.com/ticket/33273>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 9, 2021, 8:39:33 AM11/9/21
to django-...@googlegroups.com
#33273: queryset.update SQL does not receive fields from base model of inheriting
model.
-------------------------------+--------------------------------------

Reporter: James Miller | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by James Miller:

Old description:

> In an admin function, I receive a queryset with the class that was
> registered with the admin decorator, @admin.register(ForumComment), where
> the queryset is populated with ForumComments selected to approve, where
> they have been reported for moderation.
>
> In my approve_comment function, I use queryset.update(moderation=None).
> The ForumComment model extends from a Comment model in another app. When
> the code 'queryset.update(moderation=None) runs I get the following
> error:
> ```
> *** django.db.utils.OperationalError: (1054, "Unknown column
> 'django_posts_and_comments_comment.date_created' in 'order clause'"
> ```
> It seems that the queryset.update method is unable to scope the model
> 'ForumComment' to correctly include the methods/properties of the
> superclass 'Comment'.
>
> I have just returned to the code base after a while away, and I think
> that it worked, and the error is new. I have solved the error by
> iterating over the records of the queryset and saving each one
> individually using update_fields for efficiency, but the queryset.update
> should work.
>
> I have asked this question at the forum where I have included code etc.
> https://forum.djangoproject.com/t/unknown-field-in-order-clause-when-
> using-model-inheritance/10444/2
>
> In sum, should it not be the case that queryset.update is capable of
> generating SQL that will correctly include the fields of a superclass
> model?

New description:

In an admin function, I receive a queryset with the class that was
registered with the admin decorator, @admin.register(ForumComment), where
the queryset is populated with ForumComments selected to approve, where
they have been reported for moderation.

In my approve_comment function, I use queryset.update(moderation=None).
The ForumComment model extends from a Comment model in another app. When
the code 'queryset.update(moderation=None) runs I get the following error:
```
*** django.db.utils.OperationalError: (1054, "Unknown column
'django_posts_and_comments_comment.date_created' in 'order clause'"
```

It seems that the queryset.update method is unable to scope the model
'ForumComment' to correctly include the methods/properties of the
superclass 'Comment'.

I have just returned to the code base after a while away, and I think that
it worked, and the error is new. I have solved the error by iterating
over the records of the queryset and saving each one individually using
update_fields for efficiency, but the queryset.update should work.

I have asked this question at the forum where I have included code etc.
https://forum.djangoproject.com/t/unknown-field-in-order-clause-when-
using-model-inheritance/10444/2

In sum, should it not be the case that queryset.update is capable of
generating SQL that will correctly include the fields of a superclass
model?

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33273#comment:1>

Django

unread,
Nov 9, 2021, 8:43:24 AM11/9/21
to django-...@googlegroups.com
#33273: queryset.update SQL does not receive fields from base model of inheriting
model.
-------------------------------+--------------------------------------

Reporter: James Miller | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Carlton Gibson):

> I think that it worked, and the error is new

Are you able to
[https://docs.djangoproject.com/en/3.2/internals/contributing/triaging-
tickets/#bisecting-a-regression use git bisect to find where the error was
introduced] in this case?

--
Ticket URL: <https://code.djangoproject.com/ticket/33273#comment:2>

Django

unread,
Nov 10, 2021, 3:09:57 AM11/10/21
to django-...@googlegroups.com
#33273: queryset.update SQL does not receive fields from base model of inheriting
model.
-------------------------------------+-------------------------------------

Reporter: James Miller | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => needsinfo
* component: Uncategorized => Database layer (models, ORM)
* type: Uncategorized => Bug


Comment:

Hi James.

From the description here and on the forum thread, I can't see whether
this is a usage question, or expected behaviour, or a bug in Django.
If you could reduce it to a minimal sample project and upload that here,
I'm happy to have a further look.
Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/33273#comment:3>

Django

unread,
Nov 10, 2021, 5:40:19 AM11/10/21
to django-...@googlegroups.com
#33273: queryset.update SQL does not receive fields from base model of inheriting
model.
-------------------------------------+-------------------------------------

Reporter: James Miller | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by James Miller):

Hi, thanks for the response. I am not sure I could use git bisect, as I
would have to bisect the django source code, and the error occurs in my
own code. I haven't used git bisect before.
I can make a sample project, so I will do that now.

--
Ticket URL: <https://code.djangoproject.com/ticket/33273#comment:4>

Django

unread,
Nov 10, 2021, 5:54:33 AM11/10/21
to django-...@googlegroups.com
#33273: queryset.update SQL does not receive fields from base model of inheriting
model.
-------------------------------------+-------------------------------------

Reporter: James Miller | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Super. Thanks James, it makes it much easier to investigate! 👍

--
Ticket URL: <https://code.djangoproject.com/ticket/33273#comment:5>

Django

unread,
Nov 10, 2021, 8:53:24 AM11/10/21
to django-...@googlegroups.com
#33273: queryset.update SQL does not receive fields from base model of inheriting
model.
-------------------------------------+-------------------------------------

Reporter: James Miller | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by James Miller):

Ok, thanks, I found the problem. In the inheriting app's model class
Meta: I had an 'ordering' field, that referenced the base class
'date_created' field. This apparently causes problems for the admin app,
although it works fine in the view/template etc...

edit... however, only when I removed the ordering field in the Meta class
completely from both inheriting class and base class did it work.
Eventually I reinstalled django using the latest version, 3.2.9, and
everything worked fine. I forced a reinstall --no-cache-dir pip of the
version I had before, django-3.2.0 and it failed again.

It seems that the ordering clause doesn't work with the django-3.2.0, so I
reinstalled using the latest django and it is now working fine. However,
I made a sample app, and that works fine with the ordering clause and
django-3.2, so I am not sure what might be wrong in my base code, but it
works with django-3.2.9.

my sample app:
https://github.com/millerthegorilla/django_sample_app

my main app:
https://github.com/millerthegorilla/django_artisan

--
Ticket URL: <https://code.djangoproject.com/ticket/33273#comment:6>

Reply all
Reply to author
Forward
0 new messages