Make tests pass after rebase

This commit is contained in:
Raphael Michel
2026-01-22 12:48:35 +01:00
parent ff61d609ff
commit 1b083befb3
4 changed files with 28 additions and 23 deletions

View File

@@ -8,7 +8,7 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
("pretixbase", "0288_invoice_transmission"), ("pretixbase", "0296_invoice_invoice_from_state"),
] ]
operations = [ operations = [
@@ -28,7 +28,7 @@ class Migration(migrations.Migration):
("error_detail", models.TextField(null=True)), ("error_detail", models.TextField(null=True)),
("subject", models.TextField()), ("subject", models.TextField()),
("body_plain", models.TextField()), ("body_plain", models.TextField()),
("body_html", models.TextField()), ("body_html", models.TextField(null=True)),
("sender", models.CharField(max_length=500)), ("sender", models.CharField(max_length=500)),
("headers", models.JSONField(default=dict)), ("headers", models.JSONField(default=dict)),
("to", models.JSONField(default=list)), ("to", models.JSONField(default=list)),

View File

@@ -1,8 +1,8 @@
# #
# This file is part of pretix (Community Edition). # This file is part of pretix (Community Edition).
# #
# Copyright (C) 2014-2020 Raphael Michel and contributors # Copyright (C) 2014-2020 Raphael Michel and contributors
# Copyright (C) 2020-2021 rami.io GmbH and contributors # Copyright (C) 2020-today pretix GmbH and contributors
# #
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General # This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
# Public License as published by the Free Software Foundation in version 3 of the License. # Public License as published by the Free Software Foundation in version 3 of the License.
@@ -84,7 +84,7 @@ class OutgoingMail(models.Model):
subject = models.TextField() subject = models.TextField()
body_plain = models.TextField() body_plain = models.TextField()
body_html = models.TextField() body_html = models.TextField(null=True)
sender = models.CharField(max_length=500) sender = models.CharField(max_length=500)
headers = models.JSONField(default=dict) headers = models.JSONField(default=dict)
to = models.JSONField(default=list) to = models.JSONField(default=list)

View File

@@ -42,7 +42,7 @@ import smtplib
import warnings import warnings
from email.mime.image import MIMEImage from email.mime.image import MIMEImage
from email.utils import formataddr from email.utils import formataddr
from typing import Any, Dict, Sequence, Union from typing import Any, Dict, Optional, Sequence, Union
from urllib.parse import urljoin, urlparse from urllib.parse import urljoin, urlparse
from zoneinfo import ZoneInfo from zoneinfo import ZoneInfo
@@ -554,18 +554,18 @@ def mail_send_task(self, *args, outgoing_mail: int) -> bool:
retry_after = min(30 + cnt * 10, 1800) retry_after = min(30 + cnt * 10, 1800)
outgoing_mail.status = OutgoingMail.STATUS_AWAWITING_RETRY outgoing_mail.status = OutgoingMail.STATUS_AWAWITING_RETRY
outgoing_mail.save(upate_fields=["status", "error", "error_detail", "sent"]) outgoing_mail.save(update_fields=["status", "error", "error_detail", "sent"])
self.retry(max_retries=max_retries, countdown=retry_after) # throws RetryException, ends function flow self.retry(max_retries=max_retries, countdown=retry_after) # throws RetryException, ends function flow
elif retry_strategy in ("microsoft_concurrency", "quick"): elif retry_strategy in ("microsoft_concurrency", "quick"):
max_retries = 5 max_retries = 5
retry_after = [10, 30, 60, 300, 900, 900][self.request.retries] retry_after = [10, 30, 60, 300, 900, 900][self.request.retries]
outgoing_mail.status = OutgoingMail.STATUS_AWAWITING_RETRY outgoing_mail.status = OutgoingMail.STATUS_AWAWITING_RETRY
outgoing_mail.save(upate_fields=["status", "error", "error_detail", "sent"]) outgoing_mail.save(update_fields=["status", "error", "error_detail", "sent"])
self.retry(max_retries=max_retries, countdown=retry_after) # throws RetryException, ends function flow self.retry(max_retries=max_retries, countdown=retry_after) # throws RetryException, ends function flow
elif retry_strategy == "slow": elif retry_strategy == "slow":
outgoing_mail.status = OutgoingMail.STATUS_AWAWITING_RETRY outgoing_mail.status = OutgoingMail.STATUS_AWAWITING_RETRY
outgoing_mail.save(upate_fields=["status", "error", "error_detail", "sent"]) outgoing_mail.save(update_fields=["status", "error", "error_detail", "sent"])
self.retry(max_retries=5, countdown=[60, 300, 600, 1200, 1800, 1800][self.request.retries]) # throws RetryException, ends function flow self.retry(max_retries=5, countdown=[60, 300, 600, 1200, 1800, 1800][self.request.retries]) # throws RetryException, ends function flow
except MaxRetriesExceededError: except MaxRetriesExceededError:
@@ -591,7 +591,7 @@ def mail_send_task(self, *args, outgoing_mail: int) -> bool:
# If we reach this, it's a non-retryable error # If we reach this, it's a non-retryable error
outgoing_mail.status = OutgoingMail.STATUS_FAILED outgoing_mail.status = OutgoingMail.STATUS_FAILED
outgoing_mail.sent = now() outgoing_mail.sent = now()
outgoing_mail.save(upate_fields=["status", "error", "error_detail", "sent"]) outgoing_mail.save(update_fields=["status", "error", "error_detail", "sent"])
for i in invoices_to_mark_transmitted: for i in invoices_to_mark_transmitted:
i.set_transmission_failed(provider="email_pdf", data={ i.set_transmission_failed(provider="email_pdf", data={
"reason": "exception", "reason": "exception",
@@ -615,7 +615,7 @@ def mail_send_task(self, *args, outgoing_mail: int) -> bool:
outgoing_mail.error_detail = None outgoing_mail.error_detail = None
outgoing_mail.actual_attachments = actual_attachments outgoing_mail.actual_attachments = actual_attachments
outgoing_mail.sent = now() outgoing_mail.sent = now()
outgoing_mail.save(upate_fields=["status", "error", "error_detail", "sent", "actual_attachments"]) outgoing_mail.save(update_fields=["status", "error", "error_detail", "sent", "actual_attachments"])
for i in invoices_to_mark_transmitted: for i in invoices_to_mark_transmitted:
if i.transmission_status != Invoice.TRANSMISSION_STATUS_COMPLETED: if i.transmission_status != Invoice.TRANSMISSION_STATUS_COMPLETED:
i.transmission_date = now() i.transmission_date = now()
@@ -624,7 +624,7 @@ def mail_send_task(self, *args, outgoing_mail: int) -> bool:
i.transmission_info = { i.transmission_info = {
"sent": [ "sent": [
{ {
"recipients": to, "recipients": outgoing_mail.to,
"datetime": now().isoformat(), "datetime": now().isoformat(),
} }
] ]
@@ -636,7 +636,7 @@ def mail_send_task(self, *args, outgoing_mail: int) -> bool:
elif i.transmission_provider == "email_pdf": elif i.transmission_provider == "email_pdf":
i.transmission_info["sent"].append( i.transmission_info["sent"].append(
{ {
"recipients": to, "recipients": outgoing_mail.to,
"datetime": now().isoformat(), "datetime": now().isoformat(),
} }
) )
@@ -650,7 +650,7 @@ def mail_send_task(self, *args, outgoing_mail: int) -> bool:
"transmission_provider": "email_pdf", "transmission_provider": "email_pdf",
"transmission_type": "email", "transmission_type": "email",
"data": { "data": {
"recipients": [to], "recipients": outgoing_mail.to,
}, },
} }
) )

View File

@@ -26,7 +26,9 @@ from django.utils.timezone import override
from django_scopes import scope, scopes_disabled from django_scopes import scope, scopes_disabled
from pretix.base.i18n import language from pretix.base.i18n import language
from pretix.base.models import LogEntry, NotificationSetting, User from pretix.base.models import (
LogEntry, NotificationSetting, OutgoingMail, User,
)
from pretix.base.notifications import Notification, get_all_notification_types from pretix.base.notifications import Notification, get_all_notification_types
from pretix.base.services.mail import mail_send_task from pretix.base.services.mail import mail_send_task
from pretix.base.services.tasks import ProfiledTask, TransactionAwareTask from pretix.base.services.tasks import ProfiledTask, TransactionAwareTask
@@ -153,16 +155,19 @@ def send_notification_mail(notification: Notification, user: User):
tpl_plain = get_template('pretixbase/email/notification.txt') tpl_plain = get_template('pretixbase/email/notification.txt')
body_plain = tpl_plain.render(ctx) body_plain = tpl_plain.render(ctx)
mail_send_task.apply_async(kwargs={ m = OutgoingMail.objects.create(
'to': [user.email], user=user,
'subject': '[{}] {}: {}'.format( to=[user.email],
subject='[{}] {}: {}'.format(
settings.PRETIX_INSTANCE_NAME, settings.PRETIX_INSTANCE_NAME,
notification.event.settings.mail_prefix or notification.event.slug.upper(), notification.event.settings.mail_prefix or notification.event.slug.upper(),
notification.title notification.title
), ),
'body': body_plain, body_plain=body_plain,
'html': body_html, body_html=body_html,
'sender': settings.MAIL_FROM_NOTIFICATIONS, sender=settings.MAIL_FROM_NOTIFICATIONS,
'headers': {}, headers={},
'user': user.pk )
mail_send_task.apply_async(kwargs={
'outgoing_mail': m.pk,
}) })