-
Notifications
You must be signed in to change notification settings - Fork 18.1k
fix(mcp): preserve table chart state during updates #42655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
db5424a
c6f19c0
3472ea5
8f9a96a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2351,6 +2351,14 @@ class UpdateChartRequest(ChartRequestNormalizerMixin, QueryCacheControl): | |
| None, | ||
| description="Chart configuration. Optional; omit to only update chart_name.", | ||
| ) | ||
| add_columns: List[ColumnRef] | None = Field( | ||
| None, | ||
| description=( | ||
| "Table columns or metrics to append while preserving every existing " | ||
| "column and metric. Use this instead of config.columns when adding " | ||
| "columns to an existing table chart." | ||
| ), | ||
| ) | ||
| chart_name: str | None = Field( | ||
| None, | ||
| description="Auto-generates if omitted", | ||
|
|
@@ -2383,6 +2391,19 @@ class UpdateChartRequest(ChartRequestNormalizerMixin, QueryCacheControl): | |
| ), | ||
| ) | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_column_patch(self) -> "UpdateChartRequest": | ||
| """Keep full-config replacement and additive table updates unambiguous.""" | ||
| if self.config is not None and self.add_columns is not None: | ||
| raise ValueError( | ||
| "Use either 'config' for a full visualization replacement or " | ||
| "'add_columns' to append table columns while preserving the existing " | ||
| "configuration, not both." | ||
| ) | ||
|
Comment on lines
+2397
to
+2402
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test for validator error branches
The Code Review Run #b295fd Should Bito avoid suggestions like this for future reviews? (Manage Rules)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid — both branches were untested. Added in class TestUpdateChartRequestColumnPatchValidation:
def test_config_and_add_columns_together_rejected(self) # "not both"
def test_empty_add_columns_rejected(self) # "at least one column"
def test_add_columns_alone_accepted(self) # the valid shapeWriting these paid for itself: the dimension-only case they exercise led me to a real bug where appending a plain column to an aggregate table silently dropped it. Fixed in the same commit — see the PR comment.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The suggestion to add unit tests for the validator error branches is appropriate and improves the code's robustness. Implementing these tests ensures that the mutual exclusivity of 'config' and 'add_columns' is correctly enforced and helps prevent regressions, as demonstrated by the bug you identified and fixed. |
||
| if self.add_columns == []: | ||
| raise ValueError("'add_columns' must contain at least one column") | ||
| return self | ||
|
|
||
| @field_validator("chart_name") | ||
| @classmethod | ||
| def sanitize_chart_name(cls, v: str | None) -> str | None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
add_columnsfield (lines 2350-2357) has no corresponding unit tests intest_chart_schemas.py. Per the project's testing guidelines, every new MCP mutation tool schema field requires dedicated unit test coverage including request validation and schema serialization.Code Review Run #b295fd
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partly. The
add_columnsfield itself is covered —test_update_chart.pyhastest_add_columns_preserves_existing_columns_and_metrics,test_add_columns_rebinds_requested_dataset, and a parametrizedtest_add_metric_to_raw_table_returns_actionable_error. They live next to the other_build_update_payloadtests rather than intest_chart_schemas.py, which is why the search missed them.The validator was a real gap though, so I've added
TestUpdateChartRequestColumnPatchValidationcovering both error branches and the valid additive shape (see the reply on thevalidate_column_patchthread).Writing the coverage you asked for also turned up an actual bug, so thanks — details in the other thread and in the PR comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good to hear that the coverage gaps have been addressed and that the additional testing led to the discovery of a bug. The addition of
TestUpdateChartRequestColumnPatchValidationto cover both error branches and the valid additive shape is an appropriate way to resolve the concern regarding missing test coverage for the new field.