Skip to content

Raise UndiscardableError from ClaimedExecution's class methods - #828

Merged
rosa merged 1 commit into
rails:mainfrom
dai199:claimed-execution-undiscardable-error
Nov 2, 2026
Merged

rosa merged 1 commit into
rails:mainfrom
dai199:claimed-execution-undiscardable-error

Conversation

@dai199

@dai199 dai199 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

ClaimedExecution.discard_all_in_batches and ClaimedExecution.discard_all_from_jobs are meant to refuse with SolidQueue::Execution::UndiscardableError, as the instance method #discard does. Both are defined inside class << self, though, and there Ruby looks UndiscardableError up in the singleton class's lexical scope (#<Class:SolidQueue::ClaimedExecution>, then SolidQueue) and the singleton class's ancestors. None of those holds the constant, which lives on SolidQueue::Execution, so both methods raise NameError instead:

NameError: uninitialized constant #<Class:SolidQueue::ClaimedExecution>::UndiscardableError

The same lookup, reduced (Ruby 3.3 and 4.0):

module SQ
  class Execution
    class UndiscardableError < StandardError; end
  end
end

module SQ
  class ClaimedExecution < Execution
    class << self
      def discard_all
        raise UndiscardableError, "no"
      end
    end
  end
end

SQ::ClaimedExecution.discard_all
# => NameError: uninitialized constant #<Class:SQ::ClaimedExecution>::UndiscardableError

This names the constant fully in both class methods, and adds a test that each raises SolidQueue::Execution::UndiscardableError. The instance method #discard is unaffected: its lookup reaches Execution through ClaimedExecution's own ancestors.

I could not run the full suite locally (its development dependencies need MySQL and PostgreSQL client libraries), so the new test is left to CI.

ClaimedExecution.discard_all_in_batches and .discard_all_from_jobs
raise UndiscardableError from inside `class << self`, where Ruby looks
the constant up in the singleton class's lexical scope and ancestors.
Neither has Execution::UndiscardableError, so both raised NameError
(uninitialized constant #<Class:SolidQueue::ClaimedExecution>::UndiscardableError)
instead of the intended error. Name the constant fully.

@rosa rosa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch! Thanks a lot @dai199!

@rosa
rosa merged commit 5bd4184 into rails:main Nov 2, 2026
51 of 58 checks passed
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