Skip to content

Commit 6cb6ff7

Browse files
authored
Don't validate when marking patient as invalid (#3529)
The patient may be invalid because the NHS number itself is invalid, and therefore we can't use `update!` because this checks the validations first. This fixes an issue we're seeing where the scheduled PDS check jobs are failing as they can't invalidate patients who's NHS numbers are invalid: https://good-machine.sentry.io/issues/6596123827/ Using `update_column` also means any callbacks or other validations aren't called, which is probably fine, but I think once all the patients in Mavis have valid NHS numbers we should revert this change to avoid potential issues in the future where callbacks or validation haven't been run.
2 parents 4f50f25 + 60763d8 commit 6cb6ff7

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

app/models/patient.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def update_from_pds!(pds_patient)
348348
def invalidate!
349349
return if invalidated?
350350

351-
update!(invalidated_at: Time.current)
351+
update_column(:invalidated_at, Time.current)
352352
end
353353

354354
def dup_for_pending_changes

spec/models/patient_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,19 @@
431431
)
432432
end
433433
end
434+
435+
context "with an invalid NHS number" do
436+
let(:patient) { create(:patient, nhs_number: nil) }
437+
438+
before do
439+
patient.nhs_number = "1234567890"
440+
patient.save!(validate: false)
441+
end
442+
443+
it "doesn't raise an error" do
444+
expect { invalidate! }.not_to raise_error
445+
end
446+
end
434447
end
435448

436449
describe "#stage_changes" do

0 commit comments

Comments
 (0)