Skip to content

Commit

Permalink
💩 [#4764] Prevent log record spam when viewing a submission in the admin
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Oct 18, 2024
1 parent d86fbae commit 565045c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/openforms/submissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SubmissionValueVariable,
TemporaryFileUpload,
)
from .pricing import InvalidPrice
from .tasks import on_post_submission_event


Expand Down Expand Up @@ -381,7 +382,14 @@ def get_price(self, obj):

@admin.display(description=_("Payment required"), boolean=True)
def get_payment_required(self, obj):
return obj.payment_required
obj._in_admin_display = True
try:
return obj.payment_required
# InvalidPrice means that pricing/payment was set up and configured, but a
# semi-expected crash happened when trying to calculate the price because of
# mis-configuration.
except InvalidPrice:
return True

Check warning on line 392 in src/openforms/submissions/admin.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/submissions/admin.py#L391-L392

Added lines #L391 - L392 were not covered by tests

def change_view(self, request, object_id, form_url="", extra_context=None):
submission = self.get_object(request, object_id)
Expand Down
4 changes: 4 additions & 0 deletions src/openforms/submissions/pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def get_submission_price(submission: Submission) -> Decimal:
try:
price = _price_from_variable(submission)
except InvalidPrice as exc:
# Dirty, dirty hack - don't create new log records when viewing this in the
# admin.
if getattr(submission, "_in_admin_display", False): # pragma: no cover
raise
logevent.price_calculation_variable_error(
submission=submission,
variable=exc.variable,
Expand Down

0 comments on commit 565045c

Please sign in to comment.