waterWang opened a new pull request, #42919: URL: https://github.com/apache/superset/pull/42919
## Summary Fixes #42912 `import_tag` catches `SQLAlchemyError` after a query-triggered autoflush failure and continues using the same SQLAlchemy `Session` without rolling back or isolating the failed per-tag operation in a SAVEPOINT. When two concurrent tag imports race on the same `TaggedObject` association (`uix_tagged_object` unique constraint), one transaction commits first and the other receives a real `UniqueViolation`. `import_tag` catches it and `continue`s, but the `Session` remains in SQLAlchemy's pending-rollback state, so the next `Session` operation raises `PendingRollbackError`. The `@transaction()` decorator on `import_tag` is a no-op when called from `ImportAssetsCommand.run()` (which is already inside a transaction), so the poisoned session is not recovered before reuse. ## Fix Wrap each per-tag operation in a SAVEPOINT via `db_session.begin_nested()`. On failure the SAVEPOINT is rolled back, the failed tag is skipped, and the `Session` remains usable for subsequent tags — the concurrent import completes without discarding unrelated imports. ## Why this approach - `begin_nested()` rolls back only the failed per-tag operation, preserving successfully-imported tags - A full outer `Session.rollback()` would discard the entire import, which the issue explicitly warns against - Mirrors the pattern used in related Session-recovery fixes (#42675, #38934, #38859) ## Testing - [ ] Test plan to be added (pending local Superset test environment) -- 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]
