Skip to content

test(mcp): fix update_dashboard test mock for embedded_uuid - #41471

Closed
gkneighb wants to merge 1 commit into
apache:masterfrom
gkneighb:fix/mcp-update-dashboard-embedded-test-mock
Closed

test(mcp): fix update_dashboard test mock for embedded_uuid#41471
gkneighb wants to merge 1 commit into
apache:masterfrom
gkneighb:fix/mcp-update-dashboard-embedded-test-mock

Conversation

@gkneighb

Copy link
Copy Markdown
Contributor

SUMMARY

#41195 added embedded_uuid=str(dashboard.embedded[0].uuid) if dashboard.embedded else None to the shared dashboard_serializer and updated the get_dashboard_info test mocks, but the update_dashboard test's _mock_dashboard helper was not updated. That helper builds a Mock with "EVERY field the serializer touches explicitly set" — except .embedded, which therefore resolved to an auto-Mock (truthy but not subscriptable). As a result the serializer hits TypeError: 'Mock' object is not subscriptable and 5 tests in test_update_dashboard.py fail on master:

  • test_update_with_no_fields_is_noop
  • test_update_title_and_slug_and_published
  • test_update_description
  • test_empty_slug_clears_slug
  • (plus one more in the same file)

This is a test-only gap. Product code is unaffected: on a real Dashboard, .embedded is a SQLAlchemy list relationship — empty → falsy → embedded_uuid=None; non-empty → embedded[0].uuid works.

The fix models .embedded as an empty list in _mock_dashboard (matching a dashboard with no embedded configuration), so the serializer resolves embedded_uuid to None, consistent with how #41195 fixed the get_dashboard_info mocks.

TESTING INSTRUCTIONS

python -m pytest tests/unit_tests/mcp_service/dashboard/tool/test_update_dashboard.py -q

Before: 5 failed, 3 passed. After: 8 passed.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

Follow-up to #41195 (test mocks only).

🤖 Generated with Claude Code

PR apache#41195 added `embedded_uuid=str(dashboard.embedded[0].uuid) if
dashboard.embedded else None` to the shared dashboard_serializer but only
updated the get_dashboard_info test mocks. update_dashboard's _mock_dashboard
left .embedded as an auto-Mock (truthy but not subscriptable), so the serializer
hit 'Mock object is not subscriptable' and 5 update_dashboard tests failed on
master. Model .embedded as an empty list (matching a real dashboard with no
embedded config) so the serializer resolves embedded_uuid to None.

Product code is unaffected: on a real Dashboard, .embedded is a list
relationship (empty -> None). Test-only fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dosubot dosubot Bot added the dashboard Namespace | Anything related to the Dashboard label Jun 27, 2026
@bito-code-review

bito-code-review Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #20ed2e

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 7da8ce2..7da8ce2
    • tests/unit_tests/mcp_service/dashboard/tool/test_update_dashboard.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 on lines +84 to +86
# dashboard_serializer reads embedded[0].uuid when truthy (added in #41195);
# model it as an empty list so the serializer resolves embedded_uuid to None.
dashboard.embedded = []

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: Because this PR modifies _mock_dashboard, add an explicit return type annotation to the function signature so the updated helper is fully typed (for example returning a Mock). [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The changed helper _mock_dashboard is a modified Python function and its signature in the final file still lacks a return type annotation. The custom rule requires updated Python functions to be fully typed, so this is a real violation.

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/mcp_service/dashboard/tool/test_update_dashboard.py
**Line:** 84:86
**Comment:**
	*Custom Rule: Because this PR modifies `_mock_dashboard`, add an explicit return type annotation to the function signature so the updated helper is fully typed (for example returning a `Mock`).

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 an explicit return type annotation to the _mock_dashboard function is correct and aligns with best practices for type safety in Python. You can resolve this by updating the function signature to include -> Mock (assuming Mock is the appropriate type from unittest.mock).

Here is the corrected function signature:

from unittest.mock import Mock

def _mock_dashboard(...) -> Mock:
    # ... existing implementation ...

Regarding other comments on this PR, the review discussion is currently empty, so there are no additional comments to address at this time.

tests/unit_tests/mcp_service/dashboard/tool/test_update_dashboard.py

def _mock_dashboard(
    # ... arguments ...
) -> Mock:

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.52%. Comparing base (ebb32de) to head (7da8ce2).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41471      +/-   ##
==========================================
+ Coverage   63.95%   64.52%   +0.56%     
==========================================
  Files        2664     2664              
  Lines      146184   146184              
  Branches    33724    33724              
==========================================
+ Hits        93497    94325     +828     
+ Misses      50972    50142     -830     
- Partials     1715     1717       +2     
Flag Coverage Δ
hive 39.22% <ø> (ø)
mysql 57.97% <ø> (ø)
postgres 58.04% <ø> (-0.01%) ⬇️
presto 40.80% <ø> (ø)
python 59.47% <ø> (+1.21%) ⬆️
sqlite 57.67% <ø> (ø)
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.

@hainenber

Copy link
Copy Markdown
Contributor

Whoops, we missed your PR to fix failing mainline branch and merged a later one. Sorry about that!

I'll be closing this and will give more attention to PR's chronology that fixing a persistent issue like breaking mainline in the future.

@hainenber hainenber closed this Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboard Namespace | Anything related to the Dashboard size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants