michael-s-molina opened a new pull request, #45059: URL: https://github.com/apache/superset/pull/45059
### SUMMARY `CreateDashboardPermalinkCommand` is a get-or-create. It derives a deterministic UUID from the user and the dashboard state (so the same user and state always map to the same permalink), looks the entry up in the key-value store, and inserts it if it is missing. The lookup and the insert are not atomic. When several identical requests arrive at the same time, each one misses the lookup and tries to insert the same UUID. One insert wins and the others violate the unique index on `key_value.uuid` (MySQL error 1062, or the equivalent PostgreSQL unique violation). The command wraps that error in `DashboardPermalinkCreateFailedError` and the API returns an HTTP 500, even though the permalink exists and is exactly what the caller asked for. **Use case.** Embedded dashboards, and any integration that creates permalinks programmatically, can issue several identical permalink creation requests at once (for example from multiple components on a page, several tabs, or a duplicated or retried client call), with the requests spread across multiple web workers. All of these requests are legitimate and should resolve to the same permalink. Under such bursts a fraction of them fail with a 500. **Fix.** The insert now runs inside a SAVEPOINT. On `IntegrityError` the savepoint is rolled back (the outer transaction stays usable), the entry created by the concurrent request is re-read, and its key is returned. If no entry is found, the error was not the expected duplicate and is re-raised, so unrelated integrity errors are not masked. This is the same pattern used elsewhere in the codebase (for example in task creation). The re-read relies on `READ COMMITTED`, which is the default isolation level Superset sets for MySQL and PostgreSQL metadata databases. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF N/A ### TESTING INSTRUCTIONS Unit tests (the concurrent-winner test fails without the change and passes with it): ```bash pytest tests/unit_tests/commands/dashboard/permalink_create_test.py ``` Manual check: send several identical `POST /api/v1/dashboard/<id>/permalink` requests at the same time as the same user, with the same body. Before this change some of them return 500 (`DashboardPermalinkCreateFailedError`); after it, all return 201 with the same permalink key. ### ADDITIONAL INFORMATION - [ ] Has associated issue: - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] Migration is atomic, supports rollback & is backwards-compatible - [ ] Confirm DB migration upgrade and downgrade tested - [ ] Runtime estimates and downtime expectations provided - [ ] Introduces new feature or API - [ ] Removes existing feature or API 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
