New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #26192 -- Fixed crash of ordering by constants on PostgreSQL. #11396
Conversation
I remembered @charettes pr about this. |
@felixxm I'm not sure this is the right approach. Somewhere between when the ticket was initially created (1.8 era) and now the SELECT ..., 'foo' AS constant ORDER BY 'foo' to SELECT ..., 'foo' AS constant ORDER BY constant Which PostgreSQL doesn't have issues with. The main difference now is that def test_order_by_constant_value(self):
qs = Article.objects.order_by(
constant=Value('1', output_field=IntegerField()),
)
list(qs) The reason for this is that Here's my take on how this could be resolved:
|
77ec256
to
22a52fd
Compare
@charettes Thanks for your analysis 🙇♂️ I added I agree that original issue can be reproduced by passing an expression directly to I also know |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks for the adjustments.
@charettes Thanks! |
40ea163
to
04d8365
Compare
Thanks Simon Charette for the review.
Ordering by constants is reasonable in some cases (e.g. in compound queries), but in the same time it can be problematic on PostgreSQL without specified output type (see ticket 26192).
IMO we should raise
FieldError
whenoutput_field
cannot be resolved.@charettes What do you think?