rails icon indicating copy to clipboard operation
rails copied to clipboard

[Fix #54591] Raise an error in order dependent finder methods when the model has no order columns

Open joshuay03 opened this issue 10 months ago • 3 comments

Motivation / Background

Fixes https://github.com/rails/rails/issues/54591 Follow-up to https://github.com/rails/rails/pull/54607

Detail

  1. Adds a new error ActiveRecord::MissingRequiredOrderError which gets raised in ActiveRecord::FinderMethods#ordered_relation (used by #last and and all find_nth* methods) when there are no order_values and no order columns to be used for the default order.
  2. Updates a similar case where ActiveRecord::IrreversibleOrderError is raised in ActiveRecord::QueryMethods#reverse_sql_order to have a message consistent with this new error.

cc @byroot

Checklist

Before submitting the PR make sure the following are checked:

  • [x] This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • [x] Tests are added or updated if you fix a bug or add a feature.
  • [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

joshuay03 avatar Feb 24 '25 14:02 joshuay03

I wonder if this should be considered breaking enough to warrant a framework default and a deprecation.

Which is debatable because this is solving a bug, but prior you'd get a somewhat unpredictable behavior but "working" behavior, now you'd get a straight error.

byroot avatar May 17 '25 09:05 byroot

I wonder if this should be considered breaking enough to warrant a framework default and a deprecation.

Which is debatable because this is solving a bug, but prior you'd get a somewhat unpredictable behavior but "working" behavior, now you'd get a straight error.

Hmm, yeah, that's a good point, I can see the argument for a deprecation notice. I will action soon 👍🏽

joshuay03 avatar May 19 '25 01:05 joshuay03

I wonder if this should be considered breaking enough to warrant a framework default and a deprecation. Which is debatable because this is solving a bug, but prior you'd get a somewhat unpredictable behavior but "working" behavior, now you'd get a straight error.

Hmm, yeah, that's a good point, I can see the argument for a deprecation notice. I will action soon 👍🏽

Action-ed! Hopefully I've done all the things right...

joshuay03 avatar May 25 '25 02:05 joshuay03

Uh, just realized this fell through the cracks, I'll try to rebase it.

byroot avatar Jul 15 '25 08:07 byroot

Thank you!

joshuay03 avatar Jul 15 '25 09:07 joshuay03