bito-code-review[bot] commented on PR #42836:
URL: https://github.com/apache/superset/pull/42836#issuecomment-5203716913
<!-- Bito Reply -->
The flagged issue is correct. Committing the transaction before executing
the hook means that if the hook fails, the dashboard remains in the database,
violating atomicity. To resolve this, you should move the hook execution before
the initial commit or wrap the operations in a try-except block to roll back
the session if the hook fails.
Here is a concise fix:
```python
db.session.add(new_dashboard)
try:
db.session.commit()
if after_create := current_app.config.get("AFTER_ASSET_CREATE"):
after_create(new_dashboard, "dashboard")
db.session.commit()
except Exception:
db.session.rollback()
raise
```
There are no other comments in this PR. Would you like me to review any
other parts of the code?
**superset/views/dashboard/views.py**
```
db.session.add(new_dashboard)
try:
db.session.commit()
if after_create := current_app.config.get("AFTER_ASSET_CREATE"):
after_create(new_dashboard, "dashboard")
db.session.commit()
except Exception:
db.session.rollback()
raise
```
--
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]