77from dataclasses import dataclass
88from enum import StrEnum
99
10- from django .db import IntegrityError , router , transaction
1110from rest_framework .request import Request
1211
1312from sentry import options
@@ -134,10 +133,6 @@ def get_action_context() -> ActionContext | None:
134133 return _action_context .get ()
135134
136135
137- class DuplicateActionError (Exception ):
138- """Raised when an idempotency_key conflicts with an existing entry."""
139-
140-
141136def publish_action (
142137 action : GroupAction ,
143138 * ,
@@ -146,11 +141,9 @@ def publish_action(
146141 organization_id : int ,
147142 project_id : int ,
148143 actor : GroupActionActor = SYSTEM_ACTOR ,
149- idempotency_key : str | None = None ,
150144) -> None :
151145 """
152- Record an issue action. Raises DuplicateActionError if an idempotency_key
153- conflicts with an existing entry.
146+ Record an issue action.
154147
155148 Use this for shallow endpoint-level actions where the request is in scope
156149 (VIEW, COMMENT, TRIGGER_AUTOFIX). For mutation sites deeper in the stack,
@@ -171,42 +164,23 @@ def publish_action(
171164 "actor_type" : actor .actor_type .name .lower (),
172165 "actor_id" : str (actor .actor_id ),
173166 "metadata" : action .dict (),
174- "idempotency_key" : idempotency_key ,
175167 },
176168 )
177169
178170 # Don't write to the database until we're confident in the action schemas.
179171 if not options .get ("issues.action-log.write-to-db" ):
180172 return
181173
182- kwargs = dict (
174+ GroupActionLogEntry . objects . create (
183175 group_id = group_id ,
184176 project_id = project_id ,
185177 type = action .get_type ().value ,
186178 actor_type = actor .actor_type .value ,
187179 actor_id = actor .actor_id ,
188180 source = source ,
189181 data = action .dict (),
190- idempotency_key = idempotency_key ,
191182 )
192183
193- if idempotency_key is None :
194- GroupActionLogEntry .objects .create (** kwargs )
195- return
196-
197- try :
198- with transaction .atomic (using = router .db_for_write (GroupActionLogEntry )):
199- GroupActionLogEntry .objects .create (** kwargs )
200- except IntegrityError as e :
201- cause = e .__cause__
202- constraint = getattr (getattr (cause , "diag" , None ), "constraint_name" , None )
203- if constraint == "uniq_groupactionlogentry_group_idempotency_key" :
204- raise DuplicateActionError (
205- f"Action already recorded for group { group_id } "
206- f"with idempotency_key={ idempotency_key !r} "
207- ) from e
208- raise
209-
210184
211185def publish_action_from_context (
212186 action : GroupAction ,
0 commit comments