sendmail: Do not copy rules with subevent when closing an event (Z#23233683) (#6156)

This commit is contained in:
pajowu
2026-05-06 15:56:06 +02:00
committed by GitHub
parent 14708eef80
commit 5bbbf0334d
3 changed files with 60 additions and 2 deletions

View File

@@ -0,0 +1,19 @@
from django.db import migrations
from django.db.models import F
def remove_cross_event_scheduled_mails(apps, schema_editor):
Rule = apps.get_model("sendmail", "Rule")
ScheduledMail = apps.get_model("sendmail", "ScheduledMail")
ScheduledMail.objects.filter(rule__subevent__isnull=False).exclude(rule__subevent__event=F('rule__event')).delete()
Rule.objects.filter(subevent__isnull=False).exclude(subevent__event=F('event')).delete()
class Migration(migrations.Migration):
dependencies = [
("sendmail", "0010_auto_20250801_1342"),
]
operations = [
migrations.RunPython(remove_cross_event_scheduled_mails),
]

View File

@@ -232,7 +232,7 @@ def sendmail_copy_data_receiver(sender, other, item_map, **kwargs):
if sender.sendmail_rules.exists(): # idempotency
return
for r in other.sendmail_rules.prefetch_related('limit_products'):
for r in other.sendmail_rules.filter(subevent__isnull=True).prefetch_related('limit_products'):
limit_products = list(r.limit_products.all())
r = copy.copy(r)
r.pk = None