Skip to content

Commit

Permalink
💚 [#2135] -- can't select_for_update nullable columns
Browse files Browse the repository at this point in the history
Fixed select_for_update in Submission.remove_sensitive_data
  • Loading branch information
sergei-maertens committed Nov 3, 2022
1 parent 38e0d94 commit 244a2d5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/openforms/submissions/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,15 @@ def remove_sensitive_data(self):
self.pseudo = ""
self.prefill_data = dict()

steps_qs = self.submissionstep_set.select_related(
"form_step",
"form_step__form_definition",
)
for submission_step in steps_qs.select_for_update():
state = self.load_execution_state()

submission_steps = {step.id: step for step in state.submission_steps}
# lock rows with select_for_update
qs = self.submissionstep_set.filter(
pk__in=submission_steps.keys()
).select_for_update()
for pk in qs.values_list("pk", flat=True):
submission_step = submission_steps[pk]
fields = submission_step.form_step.form_definition.sensitive_fields
removed_data = {key: "" for key in fields}
submission_step.data.update(removed_data)
Expand Down

0 comments on commit 244a2d5

Please sign in to comment.