Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(conversations): move the Mailgun webhook handling into services (#102205)

Julian Bez2a7a5bf46c96
diff --git a/posthog/ingress/README.md b/posthog/ingress/README.md
index 743f4ed58ed4..6cde6d1067aa 100644
--- a/posthog/ingress/README.md
+++ b/posthog/ingress/README.md
@@ -62,8 +62,8 @@ Three duties fall on the incarnation rather than on `BearerJwt`, and none is enf
| `slack` | `/api/conversations/v1/slack/interactivity` | `supporthog_interactivity` | `conversations_slack_interactivity` | `products/conversations/backend/webhook_consumers.py` |
| `pandadoc` | `/api/legal_documents/pandadoc` | `default` | `legal_documents_signatures` | `products/legal_documents/backend/webhook_consumers.py` |
| `vapi` | `/api/user_interviews/vapi_webhook/` | `default` | `user_interviews_vapi` | `products/user_interviews/backend/webhook_consumers.py` |
-| `mailgun` | `/api/conversations/v1/email/inbound` | `inbound` | none yet, the endpoint still runs its own verifier | `products/conversations/backend/api/email_events.py` |
-| `mailgun` | `/api/conversations/v1/email/outbound` | `outbound` | none yet, the endpoint still runs its own verifier | `products/conversations/backend/api/email_events.py` |
+| `mailgun` | `/api/conversations/v1/email/inbound` | `inbound` | none yet, the endpoint still runs its own verifier | `products/conversations/backend/services/mailgun_events.py` |
+| `mailgun` | `/api/conversations/v1/email/outbound` | `outbound` | none yet, the endpoint still runs its own verifier | `products/conversations/backend/services/mailgun_events.py` |
| `sns` | `/webhooks/workflows/ses-events` | `default` | `workflows_ses_events` | `products/workflows/backend/webhook_consumers.py` |
| `customerio` | `/api/projects/<team_id>/messaging/customerio/webhook/` | none | none, it is the DRF adapter path | `products/messaging/backend/api/customerio_webhook.py` |
diff --git a/products/conversations/backend/api/tests/test_customer_email_ingestion.py b/products/conversations/backend/api/tests/test_customer_email_ingestion.py
index b35567a28c44..24ee6068f146 100644
--- a/products/conversations/backend/api/tests/test_customer_email_ingestion.py
+++ b/products/conversations/backend/api/tests/test_customer_email_ingestion.py
@@ -17,13 +17,6 @@ from posthog.models.comment import Comment
from posthog.models.organization import OrganizationMembership
from posthog.models.user import User
-from products.conversations.backend.api.email_events import (
- MAX_FORWARDING_CHALLENGE_TOKENS,
- MAX_RECIPIENTS,
- _forwarding_challenge_tokens,
- _parse_addresses,
- _parse_sent_at,
-)
from products.conversations.backend.models import (
EMAIL_THREAD_COMMENT_SCOPE,
EmailChannel,
@@ -43,6 +36,13 @@ from products.conversations.backend.services.email_channel_setup import (
FORWARDING_CHALLENGE_MARKER,
create_forwarding_challenge,
)
+from products.conversations.backend.services.mailgun_events import (
+ MAX_FORWARDING_CHALLENGE_TOKENS,
+ MAX_RECIPIENTS,
+ _forwarding_challenge_tokens,
+ _parse_addresses,
+ _parse_sent_at,
+)
from products.customer_analytics.backend.facade.email_matching import recalculate_email_thread_links
@@ -62,7 +62,7 @@ class TestCustomerEmailIngestion(BaseTest):
connection_status=EmailChannelConnectionStatus.ACTIVE,
)
signature_patcher = patch(
- "products.conversations.backend.api.email_events.validate_webhook_signature",
+ "products.conversations.backend.services.mailgun_events.validate_webhook_signature",
return_value=True,
)
signature_patcher.start()
@@ -542,8 +542,8 @@ class TestCustomerEmailIngestion(BaseTest):
("secondary_error", 500, 502, False),
]
)
- @patch("products.conversations.backend.api.email_events.request_secondary_region_status")
- @patch("products.conversations.backend.api.email_events.is_primary_region", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.request_secondary_region_status")
+ @patch("products.conversations.backend.services.mailgun_events.is_primary_region", return_value=True)
def test_primary_region_checks_secondary_before_ingesting(
self,
_name: str,
@@ -675,7 +675,7 @@ class TestForwardingChallengeTokens(SimpleTestCase):
raise AssertionError("challenge extraction read beyond its limit")
request = self.factory.post("/", {"message-headers": "[]"})
- with patch("products.conversations.backend.api.email_events.json.loads", return_value=HeaderValues()):
+ with patch("products.conversations.backend.services.mailgun_events.json.loads", return_value=HeaderValues()):
tokens = _forwarding_challenge_tokens(request)
assert len(tokens) == MAX_FORWARDING_CHALLENGE_TOKENS
diff --git a/products/conversations/backend/api/tests/test_email_endpoints.py b/products/conversations/backend/api/tests/test_email_endpoints.py
index ed61e4f983ca..ced44ff8c233 100644
--- a/products/conversations/backend/api/tests/test_email_endpoints.py
+++ b/products/conversations/backend/api/tests/test_email_endpoints.py
@@ -1493,9 +1493,9 @@ class TestEmailInboundRegionRouting(BaseTest):
def _post(self, data: dict[str, str]):
return self.client.post("/api/conversations/v1/email/inbound", data=data)
- @patch("products.conversations.backend.api.email_events.proxy_to_secondary_region", return_value=True)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
- @patch("products.conversations.backend.api.email_events.is_primary_region", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.proxy_to_secondary_region", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.is_primary_region", return_value=True)
def test_proxies_to_secondary_when_token_not_found_on_primary(
self, _mock_region: MagicMock, _mock_sig: MagicMock, mock_proxy: MagicMock
):
@@ -1504,18 +1504,18 @@ class TestEmailInboundRegionRouting(BaseTest):
assert response.status_code == 200
mock_proxy.assert_called_once()
- @patch("products.conversations.backend.api.email_events.proxy_to_secondary_region", return_value=False)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
- @patch("products.conversations.backend.api.email_events.is_primary_region", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.proxy_to_secondary_region", return_value=False)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.is_primary_region", return_value=True)
def test_returns_502_when_proxy_fails(self, _mock_region: MagicMock, _mock_sig: MagicMock, mock_proxy: MagicMock):
response = self._post({"recipient": "[email protected]"})
assert response.status_code == 502
mock_proxy.assert_called_once()
- @patch("products.conversations.backend.api.email_events.proxy_to_secondary_region")
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
- @patch("products.conversations.backend.api.email_events.is_primary_region", return_value=False)
+ @patch("products.conversations.backend.services.mailgun_events.proxy_to_secondary_region")
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.is_primary_region", return_value=False)
def test_returns_404_when_token_not_found_on_secondary(
self, _mock_region: MagicMock, _mock_sig: MagicMock, mock_proxy: MagicMock
):
@@ -1596,7 +1596,7 @@ class TestEmailInboundMultiConfig(BaseTest):
domain_verified=True,
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_routes_to_correct_config(self, _mock_sig: MagicMock):
config1 = self._create_config("[email protected]", "aaa111")
self._create_config("[email protected]", "bbb222")
@@ -1617,7 +1617,7 @@ class TestEmailInboundMultiConfig(BaseTest):
assert ticket.email_config_id == config1.id
assert ticket.email_from == "[email protected]"
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_routes_to_second_config(self, _mock_sig: MagicMock):
self._create_config("[email protected]", "aaa111")
config2 = self._create_config("[email protected]", "bbb222")
@@ -1684,7 +1684,7 @@ class TestEmailInboundContent(BaseTest):
),
]
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_content_extraction(
self, _name: str, body_fields: dict[str, str], expected_content: str, _mock_sig: MagicMock
):
@@ -1708,7 +1708,7 @@ class TestEmailInboundContent(BaseTest):
assert item_context["has_full_email_content"] is False
assert mapping.full_body_plain is None
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_reply_strips_quoted_thread(self, _mock_sig: MagicMock):
base = {
"recipient": "[email protected]",
@@ -1753,7 +1753,7 @@ class TestEmailInboundContent(BaseTest):
("line_endings_only", "Same reply\nSame details", "Same reply\r\nSame details", "", None),
]
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_reply_full_body_preservation(
self,
_name: str,
@@ -2240,7 +2240,7 @@ class TestEmailInboundDmarcRewrite(BaseTest):
),
]
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_dmarc_sender_recovery(self, _name, extra_headers, expected_email, expected_name, _mock_sig):
data = self._base_data(f"<dmarc-{_name}@test.com>")
data.update(extra_headers)
@@ -2251,7 +2251,7 @@ class TestEmailInboundDmarcRewrite(BaseTest):
assert ticket.anonymous_traits["email"] == expected_email
assert ticket.anonymous_traits["name"] == expected_name
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_recovered_sender_flows_to_comment_context(self, _mock_sig: MagicMock):
data = self._base_data("<[email protected]>")
data["from"] = "'Alex Smith' via Merch <[email protected]>"
@@ -2301,13 +2301,13 @@ class TestEmailInboundSelfAddressedAutoreply(BaseTest):
("x_autoreply", {"X-Autoreply": "yes"}),
]
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_autoreply_from_the_inbox_itself_is_dropped(self, name, headers, _mock_sig):
self._post(f"<loop-{name}@posthog.com>", {"from": "PostHog Security <[email protected]>", **headers})
assert Ticket.objects.filter(team=self.team).count() == 0
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_autoreply_from_the_inbound_address_is_dropped(self, _mock_sig: MagicMock):
self._post(
@@ -2316,7 +2316,7 @@ class TestEmailInboundSelfAddressedAutoreply(BaseTest):
assert Ticket.objects.filter(team=self.team).count() == 0
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_auto_submitted_header_is_read_from_the_message_headers_blob(self, _mock_sig: MagicMock):
self._post(
@@ -2339,13 +2339,13 @@ class TestEmailInboundSelfAddressedAutoreply(BaseTest):
("auto_submitted_no", {"from": "Alex Smith <[email protected]>", "Auto-Submitted": "no"}),
]
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_self_addressed_human_mail_still_opens_a_ticket(self, name, headers, _mock_sig):
self._post(f"<human-{name}@posthog.com>", headers)
assert Ticket.objects.filter(team=self.team).count() == 1
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_external_automated_mail_still_opens_a_ticket(self, _mock_sig: MagicMock):
# Teams route infrastructure alerts to support on purpose, so being machine-generated is
# only half the test: the message also has to claim to come from the inbox itself.
@@ -2376,7 +2376,7 @@ class TestEmailInboundTeamMemberDetection(BaseTest):
def _post(self, data: dict[str, str]):
return self.client.post("/api/conversations/v1/email/inbound", data)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_team_member_reply_attribution_and_unread(self, _mock_sig: MagicMock):
self._post(
{
@@ -2417,7 +2417,7 @@ class TestEmailInboundTeamMemberDetection(BaseTest):
ticket.refresh_from_db()
assert ticket.unread_team_count == 1
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_team_member_inbound_stamps_from_email_and_no_outbox(self, _mock_sig: MagicMock):
self._post(
{
@@ -2447,7 +2447,7 @@ class TestEmailInboundTeamMemberDetection(BaseTest):
assert support_comment.item_context["author_type"] == "support"
assert EmailOutboxMessage.objects.filter(comment=support_comment).count() == 0
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_customer_inbound_stamps_from_email(self, _mock_sig: MagicMock):
self._post(
{
@@ -2472,7 +2472,7 @@ class TestEmailInboundTeamMemberDetection(BaseTest):
("spf_pass_misaligned_domain", {"sender": "[email protected]", "X-Mailgun-Spf": "Pass"}, False),
]
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_identity_verified_reflects_spf(
self, _name: str, extra_fields: dict[str, str], expected_verified: bool, _mock_sig: MagicMock
):
@@ -2489,7 +2489,7 @@ class TestEmailInboundTeamMemberDetection(BaseTest):
ticket = Ticket.objects.get(team=self.team)
assert ticket.identity_verified is expected_verified
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_no_spf_treated_as_customer(self, _mock_sig: MagicMock):
"""From header matches a team member but no SPF pass → customer."""
self._post(
@@ -2515,7 +2515,7 @@ class TestEmailInboundTeamMemberDetection(BaseTest):
assert forged.item_context["author_type"] == "customer"
assert forged.created_by is None
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_spf_pass_but_mismatched_envelope_treated_as_customer(self, _mock_sig: MagicMock):
"""SPF passes but envelope sender domain != From domain → customer."""
self._post(
@@ -2552,7 +2552,7 @@ class TestEmailInboundTeamMemberDetection(BaseTest):
("different_sender", "[email protected]", "[email protected]", False),
]
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_promotion_requires_authenticated_sender_to_match_ticket_identity(
self, _name: str, claimed_email: str, reply_sender: str, expected_verified: bool, _mock_sig: MagicMock
):
@@ -2630,7 +2630,7 @@ class TestEmailInboundCcParticipants(BaseTest):
]
)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_new_ticket_participants(self, _name, to_header, cc_header, expected, _mock_sig):
data = self._base_data(f"<cc-{_name}@test.com>")
if to_header:
@@ -2642,7 +2642,7 @@ class TestEmailInboundCcParticipants(BaseTest):
ticket = Ticket.objects.get(team=self.team)
assert ticket.cc_participants == expected
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_reply_merges_cc_participants(self, _mock_sig: MagicMock):
data1 = self._base_data("<[email protected]>")
data1["Cc"] = "[email protected]"
@@ -2697,7 +2697,7 @@ class TestEmailInboundAttachments(BaseTest):
}
@patch("products.conversations.backend.services.attachments.save_content_to_object_storage")
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_with_image_attachment(self, _mock_sig: MagicMock, mock_storage: MagicMock):
attachment = SimpleUploadedFile("photo.png", _make_png_bytes(), content_type="image/png")
@@ -2720,7 +2720,7 @@ class TestEmailInboundAttachments(BaseTest):
assert comment.item_context["email_attachments"][0]["content_type"] == "image/png"
@patch("products.conversations.backend.services.attachments.save_content_to_object_storage")
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_with_non_image_attachment(self, _mock_sig: MagicMock, mock_storage: MagicMock):
pdf = SimpleUploadedFile("invoice.pdf", b"%PDF-1.4 fake content", content_type="application/pdf")
@@ -2743,7 +2743,7 @@ class TestEmailInboundAttachments(BaseTest):
assert len(link_nodes) == 1
@patch("products.conversations.backend.services.attachments.save_content_to_object_storage")
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_with_multiple_attachments(self, _mock_sig: MagicMock, mock_storage: MagicMock):
png = SimpleUploadedFile("photo.png", _make_png_bytes(), content_type="image/png")
pdf = SimpleUploadedFile("doc.pdf", b"%PDF-1.4 content", content_type="application/pdf")
@@ -2765,8 +2765,8 @@ class TestEmailInboundAttachments(BaseTest):
assert len(comment.item_context["email_attachments"]) == 2
@patch("products.conversations.backend.services.attachments.save_content_to_object_storage")
- @patch("products.conversations.backend.api.email_events.MAX_ATTACHMENT_SIZE", 100)
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.MAX_ATTACHMENT_SIZE", 100)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_attachment_too_large_is_skipped(self, _mock_sig: MagicMock, mock_storage: MagicMock):
oversized = SimpleUploadedFile("big.bin", b"x" * 101, content_type="application/octet-stream")
@@ -2784,7 +2784,7 @@ class TestEmailInboundAttachments(BaseTest):
assert comment.item_context.get("email_attachments") is None
@patch("products.conversations.backend.services.attachments.save_content_to_object_storage")
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_without_object_storage_skips_attachments(self, _mock_sig: MagicMock, mock_storage: MagicMock):
png = SimpleUploadedFile("photo.png", _make_png_bytes(), content_type="image/png")
@@ -2801,7 +2801,7 @@ class TestEmailInboundAttachments(BaseTest):
assert comment.rich_content is None
@patch("products.conversations.backend.services.attachments.save_content_to_object_storage")
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_invalid_image_is_rejected(self, _mock_sig: MagicMock, mock_storage: MagicMock):
fake_image = SimpleUploadedFile("evil.png", b"<html>not an image</html>", content_type="image/png")
@@ -2818,7 +2818,7 @@ class TestEmailInboundAttachments(BaseTest):
assert comment.rich_content is None
@patch("products.conversations.backend.services.attachments.save_content_to_object_storage")
- @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ @patch("products.conversations.backend.services.mailgun_events.validate_webhook_signature", return_value=True)
def test_inbound_no_attachments_unchanged(self, _mock_sig: MagicMock, mock_storage: MagicMock):
data = self._base_post_data("<[email protected]>")
with self.settings(OBJECT_STORAGE_ENABLED=True):
diff --git a/products/conversations/backend/api/urls.py b/products/conversations/backend/api/urls.py
index aed75d0ea100..e9408838fbd8 100644
--- a/products/conversations/backend/api/urls.py
+++ b/products/conversations/backend/api/urls.py
@@ -2,7 +2,12 @@
from django.urls import path, re_path
-from .email_events import email_capture_handler, email_inbound_handler, email_outbound_handler
+from products.conversations.backend.services.mailgun_events import (
+ email_capture_handler,
+ email_inbound_handler,
+ email_outbound_handler,
+)
+
from .email_settings import (
EmailConfirmForwardingView,
EmailConnectView,
diff --git a/products/conversations/backend/api/email_events.py b/products/conversations/backend/services/mailgun_events.py
similarity index 99%
rename from products/conversations/backend/api/email_events.py
rename to products/conversations/backend/services/mailgun_events.py
index c571829fc687..a57f8d7607ff 100644
--- a/products/conversations/backend/api/email_events.py
+++ b/products/conversations/backend/services/mailgun_events.py
@@ -1,4 +1,4 @@
-"""Email webhook endpoints for Mailgun routes."""
+"""Mailgun email webhook endpoints, and the inbound and outbound handling behind them."""
import re
import json
diff --git a/products/conversations/backend/signals.py b/products/conversations/backend/signals.py
index 40138ae4d332..aa75aa25896c 100644
--- a/products/conversations/backend/signals.py
+++ b/products/conversations/backend/signals.py
@@ -85,7 +85,7 @@ def emit_ticket_created_event(sender, instance: Ticket, created: bool, **kwargs)
being emitted uniformly for all sources.
Deferred via `transaction.on_commit` so we don't emit phantom events for tickets
- rolled back by the email duplicate-race `IntegrityError` in `email_events.py` (or
+ rolled back by the email duplicate-race `IntegrityError` in `mailgun_events.py` (or
any future caller that wraps creation in `transaction.atomic`).
Note: `Ticket.objects.bulk_create` does NOT trigger this signal. All current callers