-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
order_by() has no effect on values()/values_list() in models registered for translation #655
Comments
Added MR #656 that demonstrates the bug |
Great work reproducing issue. I currently don't have time to debug this myself, but i have time to review a fix if you can figure it out. |
It looks like the culprit is the def _post_init(self):
self._rewrite = True
self._populate = None
if self.model and (not self.query.order_by):
if self.model._meta.ordering:
# If we have default ordering specified on the model, set it now so that
# it can be rewritten. Otherwise sql.compiler will grab it directly from _meta
ordering = []
for key in self.model._meta.ordering:
ordering.append(rewrite_order_lookup_key(self.model, key))
self.query.add_ordering(*ordering) |
Updated my MR with a proposed patch. This passes my test and the other tests in the suite. Please review #656 |
Looks good. Merged, thanks. |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
I have encounteded a bug with a model that has default ordering. I am making a query with
order_by()
without parameters to avoid ordering and then usevalues()
orvalues_list()
to extract a subset of fields. The end result is an ordered queryset.It appears that
values()
restores model's default ordering if called afterorder_by()
, except if queryset is already ordered by cystom ordering (e.g.order_by('name')
), in which case order_by is maintained.Django 3.2.16
Python 3.10
django-modeltranslation 0.18.5
The model:
Note: it is important that the model defines
ordering
To reproduce issue:
I originally raised the issue in Django bugtracker, but when it wan't reproduced, I debugged it locally and realized that the model uses translations and
modeltranslations
overridesvalues()
and does not call super().The text was updated successfully, but these errors were encountered: