codeant-ai-for-open-source[bot] commented on code in PR #45059:
URL: https://github.com/apache/superset/pull/45059#discussion_r4210191566
##########
superset/commands/dashboard/permalink/create.py:
##########
@@ -97,14 +97,30 @@ def run(self) -> str:
assert entry.id # for type checks
return encode_permalink_key(key=entry.id, salt=self.salt)
- # Create new entry with current algorithm
- entry = KeyValueDAO.create_entry(
- resource=self.resource,
- key=uuid_key,
- value=value,
- codec=self.codec,
- )
- db.session.flush()
+ # Create new entry with current algorithm.
+ #
+ # The uuid is deterministic, so concurrent identical requests (same
user,
+ # dashboard and state) all try to insert the same uuid. The lookup
above and
+ # this insert are not atomic, so the unique index is the ultimate
arbiter:
+ # the insert runs inside a SAVEPOINT and, if a concurrent request won
the
+ # race, we join the winner's entry instead of failing the request.
+ try:
+ with db.session.begin_nested():
+ entry = KeyValueDAO.create_entry(
+ resource=self.resource,
+ key=uuid_key,
+ value=value,
+ codec=self.codec,
+ )
+ db.session.flush()
+ except IntegrityError:
+ # The SAVEPOINT is rolled back and the session is still usable. The
+ # winner's row is committed by now (READ COMMITTED, the default for
+ # MySQL and PostgreSQL metadata databases), so re-read it. If
nothing
+ # is found, this was not the expected duplicate, so re-raise.
+ entry = KeyValueDAO.get_entry(self.resource, uuid_key)
Review Comment:
✅ **CodeAnt verified this suggestion was addressed in subsequent commits and
marked this thread resolved** as of `548e5aa`.
The duplicate-recovery reread now calls `get_entry(..., for_update=True)`,
using a locking read so it can see the row committed by the winning transaction
under `REPEATABLE READ`.
<sub>If that's not right, unresolve this thread and CodeAnt will leave it
open.</sub>
<!-- codeant-auto-resolve-reply -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]