Opened 3 years ago

Last modified 3 years ago

#33273 closed Bug

queryset.update SQL does not receive fields from base model of inheriting model. — at Initial Version

Reported by: James Miller Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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?

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top