bito-code-review[bot] commented on PR #44126:
URL: https://github.com/apache/superset/pull/44126#issuecomment-5612058909
<!-- Bito Reply -->
The flagged issue is correct. Because the hook runs before the transaction
commits, any side effects (like audit logs or notifications) will persist even
if the database transaction later rolls back, potentially leading to
inconsistent state. To resolve this, the hook should be executed after the
transaction has successfully committed, typically by using a database event
listener or a post-commit hook mechanism provided by the underlying ORM (e.g.,
SQLAlchemy's `after_commit` event).
**docs/admin_docs/configuration/configuring-superset.mdx**
```
def _after_asset_create(model, asset_type):
# Instead of direct execution, register a post-commit listener
db.session.connection().connection.add_listener(
'commit', lambda: audit_log.write(f"{asset_type} {model.id} created")
)
```
--
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]