Skip to content

Commit

Permalink
🐛 [#4022] Handle serialized args to celery task
Browse files Browse the repository at this point in the history
Backport-of: #4023
  • Loading branch information
SilviaAmAm authored and sergei-maertens committed Mar 19, 2024
1 parent 0528605 commit cf93c5a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/openforms/registrations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def pre_registration(submission_id: int, event: PostSubmissionEvents) -> None:
ignore_result=False,
once={"graceful": True}, # do not spam error monitoring
)
def register_submission(submission_id: int, event: PostSubmissionEvents) -> None:
def register_submission(submission_id: int, event: PostSubmissionEvents | str) -> None:
"""
Attempt to register the submission with the configured backend.
Expand Down Expand Up @@ -279,7 +279,10 @@ def register_submission(submission_id: int, event: PostSubmissionEvents) -> None
submission,
)

if config.wait_for_payment_to_register and event.on_payment_complete:
if (
config.wait_for_payment_to_register
and event == PostSubmissionEvents.on_payment_complete
):
submission.payments.update(status=PaymentStatus.registered)

submission.save_registration_status(RegistrationStatuses.success, result or {})
Expand Down
23 changes: 23 additions & 0 deletions src/openforms/registrations/tests/test_registration_hook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test the registration hook on submissions.
"""

from datetime import timedelta
from unittest.mock import patch

Expand All @@ -17,6 +18,7 @@
from openforms.forms.models import FormRegistrationBackend
from openforms.logging.models import TimelineLogProxy
from openforms.submissions.constants import PostSubmissionEvents, RegistrationStatuses
from openforms.submissions.public_references import get_random_reference
from openforms.submissions.tests.factories import SubmissionFactory

from ..base import BasePlugin
Expand Down Expand Up @@ -345,6 +347,27 @@ def test_registration_backend_invalid_options(self):
):
register_submission(submission.id, PostSubmissionEvents.on_retry)

def test_calling_registration_task_with_serialized_args(self):
submission = SubmissionFactory.create(
completed=True,
public_registration_reference=get_random_reference(),
with_completed_payment=True,
form__registration_backend="email",
form__registration_backend_options={"to_emails": ["[email protected]"]},
)

with patch(
"openforms.registrations.tasks.GlobalConfiguration.get_solo",
return_value=GlobalConfiguration(wait_for_payment_to_register=True),
):
register_submission(
submission.id, str(PostSubmissionEvents.on_payment_complete)
)

submission.refresh_from_db()

self.assertEqual(submission.registration_status, RegistrationStatuses.success)


class NumRegistrationsTest(TestCase):
@patch("openforms.plugins.registry.GlobalConfiguration.get_solo")
Expand Down

0 comments on commit cf93c5a

Please sign in to comment.