Skip to content

Warn when applying ordering to a query with pre-existing order #524

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

Merged

Conversation

tomekowal
Copy link
Contributor

@tomekowal tomekowal commented Dec 7, 2024

Hey!

This PR attempts to mitigate issue #522
I was thinking about removing the pre-existing order_by from queries, but Ecto docs mention that reading the internal structure of the query is somewhat OK, but modifying is a no go.

https://hexdocs.pm/ecto/Ecto.Query.html#__struct__/0

Users of Ecto must consider this struct as opaque and not access its field directly. Authors of adapters may read its contents, but never modify them.

Flop is not exactly an adapter, but I think similar logic applies.

Using the internal API of Ecto seems to me as a good trade for avoiding the confusion of accidentally passing a query with pre-existing order_by which leads to a very weird behaviour and a lot of confusion.

We could potentially be more strict and even raise when we have a query with pre-existing order_by, but that would be a breaking change.

Let me know what you think, I am happy to make any corrections you find necessary.

@tomekowal tomekowal requested a review from woylie as a code owner December 7, 2024 08:53
Copy link

codecov bot commented May 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.59%. Comparing base (c2aed56) to head (822fcdd).
Report is 89 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #524      +/-   ##
==========================================
- Coverage   87.67%   87.59%   -0.09%     
==========================================
  Files          15       15              
  Lines         933      935       +2     
==========================================
+ Hits          818      819       +1     
- Misses        115      116       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@woylie woylie merged commit bc55654 into woylie:main May 14, 2025
19 checks passed
@woylie
Copy link
Owner

woylie commented May 14, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants