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.
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>
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>
* 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>
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>
Comment (by Carlton Gibson):
Super. Thanks James, it makes it much easier to investigate! 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/33273#comment:5>
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>