Skip to content

Fix MiqTask.with_status_in scope chaining and scope leakage - #24004

Open
ohhAndy wants to merge 1 commit into
ManageIQ:masterfrom
ohhAndy:fix-miq-task-with-status-in-scope
Open

ohhAndy wants to merge 1 commit into
ManageIQ:masterfrom
ohhAndy:fix-miq-task-with-status-in-scope

Conversation

@ohhAndy

@ohhAndy ohhAndy commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Fixes ManageIQ/manageiq-ui-classic#9471

Introduced in #16365

Problem

Calling with_status_in on an existing relation chain silently drops all preceding WHERE clauses because the scope block returns a new relation rooted at MiqTask.all instead of merging with self:

# Prior condition (`zone = 'East'`) was completely discarded:
MiqTask.with_zone("East").with_status_in("completed_ok").to_sql
# => WHERE "miq_tasks"."state" = 'Finished' AND "miq_tasks"."status" = 'Ok'

Fix

  • Wrap the OR reduction in merge(...) so conditions are ANDed into the existing relation chain.
  • Use MiqTask.unscoped.send(...) for each branch to prevent outer/default scopes from leaking into individual OR clauses.
  • Add specs in spec/models/miq_task_spec.rb for single and multiple status chaining.

@miq-bot assign @jrafanie
@miq-bot add-label bug
@miq-bot add-reviewer @jrafanie

@miq-bot

miq-bot commented Oct 9, 2026

Copy link
Copy Markdown
Member

Checked commit ohhAndy@c191d49 with ruby 3.3.12, rubocop 1.91.0, haml-lint 0.78.0, and yamllint 1.37.1
2 files checked, 0 offenses detected
Everything looks fine. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Settings/Tasks filtering by "24 hour time period" doesn't filter by updated/started/queued timestamps (also zone and user don't filter)

3 participants