Skip to content

Use take instead of first on pg_locks association - #24032

Merged
agrare merged 1 commit into
ManageIQ:masterfrom
jrafanie:fix-8-1-missing-required-order-error
Oct 23, 2026
Merged

agrare merged 1 commit into
ManageIQ:masterfrom
jrafanie:fix-8-1-missing-required-order-error

Conversation

@jrafanie

Copy link
Copy Markdown
Member

pg_locks has no primary key, so Rails has no column to order by when we call first. Rails 8.1 raises ActiveRecord::MissingRequiredOrderError by default in that case.

wait_resource only needs any one lock, not a particular one, so take is the right call and works on every Rails version.

It worked until now because the default scope preloads the locks, so first never went to the database. Without the preload it fails:

  VmdbDatabaseConnection.unscoped.first.wait_resource
  # => ActiveRecord::MissingRequiredOrderError

Part of #23946

pg_locks has no primary key, so Rails has no column to order by when
we call first. Rails 8.1 raises ActiveRecord::MissingRequiredOrderError
by default in that case.

wait_resource only needs any one lock, not a particular one, so take is
the right call and works on every Rails version.

It worked until now because the default scope preloads the locks, so
first never went to the database. Without the preload it fails:

  VmdbDatabaseConnection.unscoped.first.wait_resource
  # => ActiveRecord::MissingRequiredOrderError

Part of ManageIQ#23946
@miq-bot

miq-bot commented Oct 22, 2026

Copy link
Copy Markdown
Member

Checked commit jrafanie@8b9e3b6 with ruby 3.3.12, rubocop 1.91.0, haml-lint 0.78.0, and yamllint 1.37.1
1 file checked, 0 offenses detected
Everything looks fine. 👍

@agrare
agrare merged commit e11c469 into ManageIQ:master Oct 23, 2026
6 checks passed
@jrafanie
jrafanie deleted the fix-8-1-missing-required-order-error branch October 23, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants