Skip to content

feat(hooks): add configurable post-creation hook for dashboards - #42836

Closed
alexandrusoare wants to merge 3 commits into
masterfrom
alexandrusoare/feat/after-asset-create-hook
Closed

feat(hooks): add configurable post-creation hook for dashboards#42836
alexandrusoare wants to merge 3 commits into
masterfrom
alexandrusoare/feat/after-asset-create-hook

Conversation

@alexandrusoare

Copy link
Copy Markdown
Contributor

SUMMARY

Adds an AFTER_ASSET_CREATE config callback that fires after a new dashboard is persisted. This allows downstream integrations (e.g. auto-categorization, audit logging, notification triggers) to react to asset creation without modifying core views. The hook receives the model instance and the asset type string ("dashboard")

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • 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

@dosubot dosubot Bot added change:backend Requires changing the backend dashboard Namespace | Anything related to the Dashboard labels Aug 6, 2026
@bito-code-review

bito-code-review Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #0b9552

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/views/dashboard/views.py - 1
    • Inconsistent commit pattern · Line 98-100
      The view layer commits after the `AFTER_ASSET_CREATE` hook (line 100), but the same pattern in `commands/dashboard/create.py` (line 56-57) and `commands/chart/create.py` (line 62-63) does not. This inconsistency could cause duplicate commits if the hook performs database operations.
Review Details
  • Files reviewed - 1 · Commit Range: 22eb37d..22eb37d
    • superset/views/dashboard/views.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/views/dashboard/views.py Outdated
Comment on lines +98 to +100
if after_create := current_app.config.get("AFTER_ASSET_CREATE"):
after_create(new_dashboard, "dashboard")
db.session.commit()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The dashboard is committed before AFTER_ASSET_CREATE runs. If the hook raises an exception, the request fails but the dashboard remains permanently persisted, so the creation is not atomic and cannot be rolled back. Invoke the hook before the transaction's commit, or explicitly roll back and remove the dashboard when the hook fails. [logic error]

Severity Level: Major ⚠️
- ❌ Dashboard creation requests fail when configured hooks raise exceptions.
- ⚠️ Failed requests leave orphaned untitled dashboards persisted.
- ⚠️ Downstream integrations can make UI creation appear unsuccessful.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/views/dashboard/views.py
**Line:** 98:100
**Comment:**
	*Logic Error: The dashboard is committed before `AFTER_ASSET_CREATE` runs. If the hook raises an exception, the request fails but the dashboard remains permanently persisted, so the creation is not atomic and cannot be rolled back. Invoke the hook before the transaction's commit, or explicitly roll back and remove the dashboard when the hook fails.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

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:

        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

@alexandrusoare alexandrusoare reopened this Aug 6, 2026
@github-actions github-actions Bot removed the github_actions Pull requests that update GitHub Actions code label Aug 6, 2026
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.73%. Comparing base (76e6909) to head (1f992d7).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
superset/views/dashboard/views.py 25.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42836      +/-   ##
==========================================
+ Coverage   56.18%   65.73%   +9.54%     
==========================================
  Files        2843     2843              
  Lines      162653   162656       +3     
  Branches    37239    37240       +1     
==========================================
+ Hits        91380   106914   +15534     
+ Misses      70430    53649   -16781     
- Partials      843     2093    +1250     
Flag Coverage Δ
hive 37.95% <25.00%> (-0.01%) ⬇️
mysql 57.78% <25.00%> (?)
postgres 57.83% <25.00%> (?)
presto 39.86% <25.00%> (-0.01%) ⬇️
python 59.20% <25.00%> (+19.28%) ⬆️
sqlite 57.46% <25.00%> (?)
unit 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend dashboard Namespace | Anything related to the Dashboard size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant