-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat(GAL): Add idempotency key to publish functions #119534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| import logging | ||
| from typing import Any, assert_never, cast | ||
|
|
||
| from django.db import router, transaction | ||
| from django.db import IntegrityError, router, transaction | ||
| from django.dispatch import receiver | ||
|
|
||
| from sentry.audit_log.services.log import AuditLogEvent, UserIpEvent, log_rpc_service | ||
|
|
@@ -346,24 +346,31 @@ def process_group_action_log_event(payload: GroupActionLogPayload, **kwds: Any) | |
| """Write a GroupActionLogEntry from the outbox payload, then trigger | ||
| derived data processing.""" | ||
| try: | ||
| using = router.db_for_write(GroupActionLogEntry) | ||
|
|
||
| group_id = payload["group_id"] | ||
| force_async_derived = payload["force_async_derived"] | ||
|
|
||
| GroupActionLogEntry.objects.create( | ||
| group_id=group_id, | ||
| project_id=payload["project_id"], | ||
| type=payload["type"], | ||
| actor_type=payload["actor_type"], | ||
| actor_id=payload["actor_id"], | ||
| source=payload["source"], | ||
| data=payload["data"], | ||
| ) | ||
| try: | ||
| with transaction.atomic(using=using): | ||
| GroupActionLogEntry.objects.create( | ||
| group_id=group_id, | ||
| project_id=payload["project_id"], | ||
| type=payload["type"], | ||
| actor_type=payload["actor_type"], | ||
| actor_id=payload["actor_id"], | ||
| source=payload["source"], | ||
| data=payload["data"], | ||
| idempotency_key=payload.get("idempotency_key"), | ||
| ) | ||
| except IntegrityError: | ||
| # Idempotency conflict; we treat this as a no-op. | ||
| pass | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate key still triggers processingMedium Severity After an idempotency Reviewed by Cursor Bugbot for commit cfe21de. Configure here. |
||
|
|
||
| # This receiver runs inside the outbox drain transaction | ||
| # (process_shard → transaction.atomic), so the GALE is not yet committed. | ||
| # Defer to on_commit so the GALE is visible to readers on other connections. | ||
| strategy = ProcessingStrategy.ASYNC if force_async_derived else ProcessingStrategy.INLINE | ||
| using = router.db_for_write(GroupActionLogEntry) | ||
| transaction.on_commit( | ||
| lambda: trigger_group_log_processing(group_id, strategy=strategy), using=using | ||
| ) | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.