Skip to content

Commit

Permalink
deep_dup serialized job data instead ofattr_readonly to prevent o…
Browse files Browse the repository at this point in the history
…verwriting (#363)
  • Loading branch information
bensheldon authored Sep 6, 2021
1 parent d68de09 commit 6b0dc43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
12 changes: 5 additions & 7 deletions lib/good_job/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class Job < Object.const_get(GoodJob.active_record_parent_class)
self.table_name = 'good_jobs'
self.advisory_lockable_column = 'active_job_id'

attr_readonly :serialized_params

# Parse a string representing a group of queues into a more readable data
# structure.
# @param string [String] Queue string
Expand Down Expand Up @@ -277,14 +275,14 @@ def executable?

# @return [ExecutionResult]
def execute
params = serialized_params.merge(
"provider_job_id" => id
)

GoodJob::CurrentExecution.reset
GoodJob::CurrentExecution.good_job = self

job_data = serialized_params.deep_dup
job_data["provider_job_id"] = id

ActiveSupport::Notifications.instrument("perform_job.good_job", { good_job: self, process_id: GoodJob::CurrentExecution.process_id, thread_name: GoodJob::CurrentExecution.thread_name }) do
value = ActiveJob::Base.execute(params)
value = ActiveJob::Base.execute(job_data)

if value.is_a?(Exception)
handled_error = value
Expand Down
7 changes: 1 addition & 6 deletions spec/lib/good_job/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,11 @@ def perform(result_value = nil, raise_error: false)
before do
TestJob.retry_on(TestJob::ExpectedError, attempts: 1)

original_attr_readonly = described_class._attr_readonly
described_class._attr_readonly = Set.new

good_job.serialized_params["exception_executions"] = { "[TestJob::ExpectedError]" => 1 }
good_job.save!

described_class._attr_readonly = original_attr_readonly
end

it 'does not modify the good_job serialized params' do
it 'does not modify the original good_job serialized params' do
expect do
good_job.perform
end.not_to change { good_job.reload.serialized_params["exception_executions"]["[TestJob::ExpectedError]"] }
Expand Down

0 comments on commit 6b0dc43

Please sign in to comment.