Skip to content

fix(cli): avoid DetachedInstanceError in compute-thumbnails#41530

Merged
rusackas merged 6 commits into
apache:masterfrom
carlosribeiro-plaid:fix-compute-thumbnails-detached-instance
Jul 10, 2026
Merged

fix(cli): avoid DetachedInstanceError in compute-thumbnails#41530
rusackas merged 6 commits into
apache:masterfrom
carlosribeiro-plaid:fix-compute-thumbnails-detached-instance

Conversation

@carlosribeiro-plaid

Copy link
Copy Markdown
Contributor

SUMMARY

superset compute-thumbnails crashes with DetachedInstanceError when more than one model is processed (e.g. superset compute-thumbnails -d -i 8 -i 12).

compute_generic_thumbnail queries the models, then inside the loop builds the progress message with an f-string that interpolates the ORM instance (f'... "{model}" ...'). Computing a thumbnail (cache_dashboard_thumbnail / cache_chart_thumbnail) can close/expire the SQLAlchemy session, so on the next iteration the instance is detached and str(model) raises:

sqlalchemy.orm.exc.DetachedInstanceError: Instance <Dashboard at 0x...> is not bound to a Session; attribute refresh operation cannot proceed

The fix materializes the (id, label) pairs up front, before any thumbnail is computed, then iterates over plain values — so the loop never touches a detached ORM instance. No behavior change otherwise.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A (CLI bug fix).

TESTING INSTRUCTIONS

  1. With thumbnails enabled, run superset compute-thumbnails -d -i <id1> -i <id2> (two or more ids).
  2. Before: it processes the first model, then crashes with DetachedInstanceError.
  3. After: all requested models are processed.

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

@bito-code-review

bito-code-review Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #d49e9f

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 1f66b53..1f66b53
    • superset/cli/thumbnails.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

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

⚠️ Translation Regression Detected

A source change in this PR renamed or reworded strings, invalidating existing translations (they are now #, fuzzy) in ar, it, ko, pt. Please resolve the affected .po files before merging.

Note: intentionally deleting a translatable string is not a regression and is not flagged here — only translations invalidated by a renamed/reworded source string are.

Language Fuzzy before Fuzzy after New
ar 1130 1133 +3
it 1660 1662 +2
ko 1514 1516 +2
pt 1835 1837 +2

How to fix

1. Install dependencies (if not already set up):

pip install -r superset/translations/requirements.txt
sudo apt-get install gettext   # or: brew install gettext

2. Re-extract strings and sync .po files:

./scripts/translations/babel_update.sh

This rewrites superset/translations/messages.pot from the current source files and merges the changes into every .po file. Strings whose msgid changed will be marked #, fuzzy.

3. Resolve the fuzzy entries in the affected language files (ar, it, ko, pt):

grep -n '#, fuzzy' superset/translations/<lang>/LC_MESSAGES/messages.po

For each fuzzy entry, either rewrite the msgstr to match the new string and remove the #, fuzzy line, or clear the msgstr to "" if you cannot provide a translation.

4. Commit your changes to the .po files.

@sadpandajoe
sadpandajoe requested a review from rusackas June 29, 2026 17:28
Comment thread superset/cli/thumbnails.py Outdated
Comment on lines +88 to +95
items = [(model.id, str(model)) for model in query.all()]
count = len(items)
if asynchronous:
func = compute_func.delay
action = "Triggering"
else:
func = compute_func
action = "Processing"

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: Add explicit type annotations for the newly introduced local variables to comply with the type-hinting requirement. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The added local variables items, count, func, and action are all inferred from context and can be explicitly annotated, so this matches the type-hinting rule for newly introduced Python code without type hints.

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/cli/thumbnails.py
**Line:** 88:95
**Comment:**
	*Custom Rule: Add explicit type annotations for the newly introduced local variables to comply with the type-hinting requirement.

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 suggestion to add explicit type annotations is correct and improves code readability and maintainability. You can resolve this by adding the following type hints to the variables in superset/cli/thumbnails.py:

        items: list[tuple[int, str]] = [(model.id, str(model)) for model in query.all()]
        count: int = len(items)
        if asynchronous:
            func: Callable = compute_func.delay
            action: str = "Triggering"
        else:
            func: Callable = compute_func
            action: str = "Processing"

There are no other comments on this PR. Would you like me to check for any other potential type-hinting improvements in this file?

superset/cli/thumbnails.py

items: list[tuple[int, str]] = [(model.id, str(model)) for model in query.all()]
        count: int = len(items)
        if asynchronous:
            func: Callable = compute_func.delay
            action: str = "Triggering"
        else:
            func: Callable = compute_func
            action: str = "Processing"

@rad-pat

rad-pat commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@rusackas as requested

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.56%. Comparing base (43bfc85) to head (d958844).

Files with missing lines Patch % Lines
superset/cli/thumbnails.py 75.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41530      +/-   ##
==========================================
- Coverage   64.57%   64.56%   -0.01%     
==========================================
  Files        2718     2718              
  Lines      151528   151529       +1     
  Branches    34819    34819              
==========================================
- Hits        97845    97839       -6     
- Misses      51854    51858       +4     
- Partials     1829     1832       +3     
Flag Coverage Δ
hive 39.07% <16.66%> (+<0.01%) ⬆️
mysql 57.43% <75.00%> (+<0.01%) ⬆️
postgres 57.49% <75.00%> (-0.01%) ⬇️
presto 40.57% <16.66%> (+<0.01%) ⬆️
python 58.89% <75.00%> (-0.01%) ⬇️
sqlite 57.09% <75.00%> (+<0.01%) ⬆️
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.

@pull-request-size pull-request-size Bot added size/L and removed size/S labels Jun 30, 2026
Comment thread tests/unit_tests/cli/thumbnails_test.py Outdated
Comment on lines +31 to +34
def __init__(self, pk: int, label: str) -> None:
self.id = pk
self._label = label
self.detached = False

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: Add explicit type annotations for the instance attributes in the initializer so the new class fully complies with the type-hinting rule. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The new class defines instance attributes in Python without annotations even though their types are clear and can be annotated. This matches the type-hinting rule for relevant variables in newly introduced Python code.

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:** tests/unit_tests/cli/thumbnails_test.py
**Line:** 31:34
**Comment:**
	*Custom Rule: Add explicit type annotations for the instance attributes in the initializer so the new class fully complies with the type-hinting rule.

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
👍 | 👎

@netlify

netlify Bot commented Jun 30, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit d958844
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a5048c67a659f00083d040e
😎 Deploy Preview https://deploy-preview-41530--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #4614c3

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 1f66b53..433a3a2
    • tests/unit_tests/cli/thumbnails_test.py
    • superset/cli/thumbnails.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

@carlosribeiro-plaid
carlosribeiro-plaid force-pushed the fix-compute-thumbnails-detached-instance branch from fddd08d to 9441669 Compare July 1, 2026 13:00
func = compute_func
action = "Processing"
for i, (model_pk, label) in enumerate(items):
msg = f'{action} {friendly_type} "{label}" ({i + 1}/{count})'

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: Add an explicit type annotation for this newly introduced local variable to comply with the rule requiring type hints on relevant annotatable variables. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is a newly introduced local variable that can clearly be annotated as str, but it is assigned without a type hint. That matches the rule requiring type hints on relevant annotatable variables.

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/cli/thumbnails.py
**Line:** 100:100
**Comment:**
	*Custom Rule: Add an explicit type annotation for this newly introduced local variable to comply with the rule requiring type hints on relevant annotatable variables.

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
👍 | 👎

compute loop, so building the progress message never touches a detached
instance even when several models are processed.
"""
models = [_FakeModel(1, "Dashboard A"), _FakeModel(2, "Dashboard B")]

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: Add an explicit type annotation for this local collection variable to satisfy the type-hinting requirement for relevant variables. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The new code introduces a local collection variable without an explicit type hint, and the rule requires type hints on relevant Python variables that can be annotated. This is a real omission in the added code.

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:** tests/unit_tests/cli/thumbnails_test.py
**Line:** 52:52
**Comment:**
	*Custom Rule: Add an explicit type annotation for this local collection variable to satisfy the type-hinting requirement for relevant variables.

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
👍 | 👎

"""
models = [_FakeModel(1, "Dashboard A"), _FakeModel(2, "Dashboard B")]

query = mocker.MagicMock()

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: Add a type annotation to this mock variable so the new code does not omit type hints on relevant local variables. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The mock variable is newly introduced and has no explicit type hint. Since the rule flags relevant variables that can be annotated, this is a valid type-hint omission.

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:** tests/unit_tests/cli/thumbnails_test.py
**Line:** 54:54
**Comment:**
	*Custom Rule: Add a type annotation to this mock variable so the new code does not omit type hints on relevant local variables.

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
👍 | 👎

side_effect=_detach_session,
)

result = CliRunner().invoke(thumbnails.compute_thumbnails, ["-d"])

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: Add a type annotation for this command invocation result variable to comply with the type-hint rule for relevant variables. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The invocation result is stored in a new local variable without a type hint. Under the stated rule, this is a valid omission because the variable can be annotated.

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:** tests/unit_tests/cli/thumbnails_test.py
**Line:** 70:70
**Comment:**
	*Custom Rule: Add a type annotation for this command invocation result variable to comply with the type-hint rule for relevant variables.

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

bito-code-review Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #c60ad8

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: c99328c..9441669
    • superset/cli/thumbnails.py
    • tests/unit_tests/cli/thumbnails_test.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

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @carlosribeiro-plaid. Clean fix and the test covers the detach mid-loop rather than just asserting the refactor. LGTM.

The codeant nitpicks about missing type hints on msg and the test's local vars aren't worth blocking on, those are all trivially inferred by mypy already.

@rusackas rusackas added the merge-if-green If approved and tests are green, please go ahead and merge it for me label Jul 10, 2026
@rusackas
rusackas merged commit 2380d57 into apache:master Jul 10, 2026
61 checks passed
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

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

Labels

merge-if-green If approved and tests are green, please go ahead and merge it for me size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants