You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "aminghadersohi (via GitHub)" <gi...@apache.org> on 2025/11/26 00:13:33 UTC
[PR] fix(mcp): fix dataset tool tests using incorrect calling pattern [superset]
aminghadersohi opened a new pull request, #36279:
URL: https://github.com/apache/superset/pull/36279
### SUMMARY
Two tests in `TestDatasetSortableColumns` were failing with `AttributeError: 'function' object has no attribute 'fn'` because they were trying to call `list_datasets.fn()` directly.
The `@tool` and `@parse_request` decorators don't expose a `.fn` attribute on the decorated function. The correct way to test MCP tools is to use the FastMCP `Client` pattern.
**Fixed tests:**
- `test_list_datasets_with_valid_order_column` - tests list_datasets with valid sortable column
- `test_default_ordering` - tests default ordering behavior when no order_column is specified
Both tests now use `async with Client(mcp_server)` and `client.call_tool()` to properly invoke the MCP tool, matching the pattern used in all other MCP service tests.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - test fix only
### TESTING INSTRUCTIONS
1. Run the failing tests before fix:
```bash
pytest tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py::TestDatasetSortableColumns::test_list_datasets_with_valid_order_column
pytest tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py::TestDatasetSortableColumns::test_default_ordering
```
Both should fail with `AttributeError: 'function' object has no attribute 'fn'`
2. Run all MCP service tests to verify fix and no regressions:
```bash
pytest tests/unit_tests/mcp_service
```
All 240 tests should pass.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] 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
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): fix dataset tool tests using incorrect calling pattern [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #36279:
URL: https://github.com/apache/superset/pull/36279#issuecomment-3578156505
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): fix dataset tool tests using incorrect calling pattern [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #36279:
URL: https://github.com/apache/superset/pull/36279#discussion_r2562103325
##########
tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py:
##########
@@ -1201,27 +1199,24 @@ def test_sortable_columns_in_docstring(self):
assert col in list_datasets.__doc__
@patch("superset.daos.dataset.DatasetDAO.list")
- @patch("superset.mcp_service.auth.get_user_from_request")
@pytest.mark.asyncio
- async def test_default_ordering(self, mock_get_user, mock_dataset_list):
+ async def test_default_ordering(self, mock_list, mcp_server):
"""Test default ordering behavior for datasets."""
- from superset.mcp_service.dataset.tool.list_datasets import list_datasets
-
- mock_get_user.return_value = MagicMock(id=1)
- # Mock the DAO to return empty list and count
- mock_dataset_list.return_value = ([], 0)
- mock_ctx = MagicMock()
- mock_ctx.info = AsyncMock()
- mock_ctx.debug = AsyncMock()
- mock_ctx.error = AsyncMock()
- request = ListDatasetsRequest() # No order specified
- await list_datasets(request, mock_ctx)
-
- # When order_column is None, the default "changed_on" is used by ModelListCore
- call_args = mock_dataset_list.call_args[1]
- assert (
- call_args["order_column"] == "changed_on"
- ) # Default applied by ModelListCore
- assert (
- call_args["order_direction"] == "desc"
- ) # From ListDatasetsRequest default
+ # Create mock dataset
+ dataset = create_mock_dataset(
+ dataset_id=1, table_name="Test Dataset", schema="main"
+ )
+ mock_list.return_value = ([dataset], 1)
+
+ async with Client(mcp_server) as client:
+ # Test with no order specified
+ request = ListDatasetsRequest() # No order specified
+ result = await client.call_tool(
+ "list_datasets", {"request": request.model_dump()}
+ )
+ assert result.content is not None
+ data = json.loads(result.content[0].text)
+ assert data["datasets"] is not None
+ assert len(data["datasets"]) == 1
+ # Verify the mock was called
+ mock_list.assert_called_once()
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incomplete test assertions for ordering parameters</b></div>
<div id="fix">
The test for valid order column does not verify that DatasetDAO.list is called with the correct order_column and order_direction parameters. This could allow regressions where the ordering logic fails without detection. Add assertions to check the call arguments match the expected values.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
# Verify the mock was called
mock_list.assert_called_once()
call_args = mock_list.call_args
assert call_args.kwargs["order_column"] == "table_name"
assert call_args.kwargs["order_direction"] == "asc"
````
</div>
</details>
</div>
<small><i>Code Review Run <a href=https://github.com/apache/superset/pull/36279#issuecomment-3578156505>#54e06e</a></i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py:
##########
@@ -1201,27 +1199,24 @@ def test_sortable_columns_in_docstring(self):
assert col in list_datasets.__doc__
@patch("superset.daos.dataset.DatasetDAO.list")
- @patch("superset.mcp_service.auth.get_user_from_request")
@pytest.mark.asyncio
- async def test_default_ordering(self, mock_get_user, mock_dataset_list):
+ async def test_default_ordering(self, mock_list, mcp_server):
"""Test default ordering behavior for datasets."""
- from superset.mcp_service.dataset.tool.list_datasets import list_datasets
-
- mock_get_user.return_value = MagicMock(id=1)
- # Mock the DAO to return empty list and count
- mock_dataset_list.return_value = ([], 0)
- mock_ctx = MagicMock()
- mock_ctx.info = AsyncMock()
- mock_ctx.debug = AsyncMock()
- mock_ctx.error = AsyncMock()
- request = ListDatasetsRequest() # No order specified
- await list_datasets(request, mock_ctx)
-
- # When order_column is None, the default "changed_on" is used by ModelListCore
- call_args = mock_dataset_list.call_args[1]
- assert (
- call_args["order_column"] == "changed_on"
- ) # Default applied by ModelListCore
- assert (
- call_args["order_direction"] == "desc"
- ) # From ListDatasetsRequest default
+ # Create mock dataset
+ dataset = create_mock_dataset(
+ dataset_id=1, table_name="Test Dataset", schema="main"
+ )
+ mock_list.return_value = ([dataset], 1)
+
+ async with Client(mcp_server) as client:
+ # Test with no order specified
+ request = ListDatasetsRequest() # No order specified
+ result = await client.call_tool(
+ "list_datasets", {"request": request.model_dump()}
+ )
+ assert result.content is not None
+ data = json.loads(result.content[0].text)
+ assert data["datasets"] is not None
+ assert len(data["datasets"]) == 1
+ # Verify the mock was called
+ mock_list.assert_called_once()
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incomplete test assertions for default ordering</b></div>
<div id="fix">
The test for default ordering does not verify that DatasetDAO.list is called with the correct default order_column and order_direction parameters. This could allow regressions where default ordering fails. Add assertions to check the call arguments use the expected defaults.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
# Verify the mock was called
mock_list.assert_called_once()
call_args = mock_list.call_args
assert call_args.kwargs["order_column"] == "changed_on"
assert call_args.kwargs["order_direction"] == "desc"
````
</div>
</details>
</div>
<small><i>Code Review Run <a href=https://github.com/apache/superset/pull/36279#issuecomment-3578156505>#54e06e</a></i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): fix dataset tool tests using incorrect calling pattern [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi closed pull request #36279: fix(mcp): fix dataset tool tests using incorrect calling pattern
URL: https://github.com/apache/superset/pull/36279
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): fix dataset tool tests using incorrect calling pattern [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on PR #36279:
URL: https://github.com/apache/superset/pull/36279#issuecomment-3578164934
Closing this PR as upstream already fixed the same issue in commit ab36bd3965 (PR #36251). The fix calls list_datasets() directly instead of list_datasets.fn(), which resolves the AttributeError.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): fix dataset tool tests using incorrect calling pattern [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #36279:
URL: https://github.com/apache/superset/pull/36279#issuecomment-3578186290
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/36279?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 48.04%. Comparing base ([`76d897e`](https://app.codecov.io/gh/apache/superset/commit/76d897eaa2f9e137102bc194c2e3109c29d0348f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`6a384ed`](https://app.codecov.io/gh/apache/superset/commit/6a384ed33e42a97621ddb973a7d0131e5e7c4aa3?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 2967 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #36279 +/- ##
===========================================
- Coverage 60.48% 48.04% -12.44%
===========================================
Files 1931 636 -1295
Lines 76236 46817 -29419
Branches 8568 5081 -3487
===========================================
- Hits 46114 22495 -23619
+ Misses 28017 23671 -4346
+ Partials 2105 651 -1454
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/36279/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/36279/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `43.75% <ø> (-5.41%)` | :arrow_down: |
| [javascript](https://app.codecov.io/gh/apache/superset/pull/36279/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/36279/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `47.35% <ø> (-6.46%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/36279/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `48.04% <ø> (-15.47%)` | :arrow_down: |
| [unit](https://app.codecov.io/gh/apache/superset/pull/36279/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `100.00% <ø> (+42.36%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/36279?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org