From 2ac376ba654ebba30ff31432ca2b78572340f07c Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Thu, 5 Dec 2024 17:47:00 +0100 Subject: [PATCH] :adhesive_bandage: [#4320] Fix crash when rendering PDF again for cosigned submission The PDF was including the cosign data/component for version 1 of cosign, which is not compatible at all with v2 (see #4308), causing crashes. Generally this doesn't matter since the PDF is generated right after submission is received and before its cosigned, and we don't usually need to re-generate it except during development. --- src/openforms/submissions/report.py | 6 ++++++ .../submissions/tests/test_tasks_pdf.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/openforms/submissions/report.py b/src/openforms/submissions/report.py index 6d1fe18fb3..5eb30e722b 100644 --- a/src/openforms/submissions/report.py +++ b/src/openforms/submissions/report.py @@ -59,6 +59,12 @@ def co_signer(self) -> str: if not (co_sign_data := self.submission.co_sign_data): return "" + # XXX this is something present in cosign v2 but not v1, which happens after the + # PDF is generated. Generating the PDF again after it's cosigned otherwise + # crashes. + if "cosign_date" in co_sign_data: + return "" + representation = co_sign_data.get("representation") or "" identifier = co_sign_data["identifier"] co_sign_auth_attribute = co_sign_data["co_sign_auth_attribute"] diff --git a/src/openforms/submissions/tests/test_tasks_pdf.py b/src/openforms/submissions/tests/test_tasks_pdf.py index d641affe0f..7dc8ab0519 100644 --- a/src/openforms/submissions/tests/test_tasks_pdf.py +++ b/src/openforms/submissions/tests/test_tasks_pdf.py @@ -559,3 +559,19 @@ def test_incomplete_cosign_data_missing_representation(self): ), ) self.assertIn(identifier, rendered) + + def test_cosign_v2_data(self): + report = SubmissionReportFactory.create( + content="", + submission__completed=True, + submission__co_sign_data={ + "plugin": "digid", + "attribute": "bsn", + "value": "123456782", + "cosign_date": "2024-01-01T17:00:00Z", + }, + ) + + html: str = report.generate_submission_report_pdf() + + self.assertNotEqual(html, "")