Skip to content

Conversation

@aminghadersohi
Copy link
Contributor

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:

    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:

    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)
    • 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

Two tests in TestDatasetSortableColumns were failing because they were
attempting to call list_datasets.fn() directly, which doesn't exist on
the decorated function object. The @tool and @parse_request decorators
don't expose a .fn attribute.

Fixed by updating both tests to use the correct MCP client pattern:
- test_list_datasets_with_valid_order_column
- test_default_ordering

Both tests now properly use async with Client(mcp_server) and
client.call_tool() to invoke the list_datasets tool, matching the
pattern used in all other MCP service tests.
@aminghadersohi
Copy link
Contributor Author

Closing this PR as upstream already fixed the same issue in commit ab36bd3 (PR #36251). The fix calls list_datasets() directly instead of list_datasets.fn(), which resolves the AttributeError.

Copy link
Contributor

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

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

Code Review Agent Run #54e06e

Actionable Suggestions - 2
  • tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py - 2
Additional Suggestions - 4
  • tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py - 4
    • Missing return type annotation · Line 1165-1165
      Function `test_list_datasets_with_valid_order_column` at line 1165 is missing a return type annotation. Add `-> None` to the function signature.
      Code suggestion
       @@ -1165,1 +1165,1 @@
      -    async def test_list_datasets_with_valid_order_column(self, mock_list, mcp_server):
      +    async def test_list_datasets_with_valid_order_column(self, mock_list, mcp_server) -> None:
    • Missing return type annotation · Line 1188-1188
      Function `test_sortable_columns_in_docstring` at line 1188 is missing a return type annotation. Add `-> None` to the function signature.
      Code suggestion
       @@ -1188,1 +1188,1 @@
      -    def test_sortable_columns_in_docstring(self):
      +    def test_sortable_columns_in_docstring(self) -> None:
    • Missing return type annotation · Line 1203-1203
      Function `test_default_ordering` at line 1203 is missing a return type annotation. Add `-> None` to the function signature.
      Code suggestion
       @@ -1203,1 +1203,1 @@
      -    async def test_default_ordering(self, mock_list, mcp_server):
      +    async def test_default_ordering(self, mock_list, mcp_server) -> None:
    • Trailing comma missing in function call · Line 1169-1169
      Line 1169 is missing a trailing comma after the last argument. Add a trailing comma after `schema="main"` for consistency.
      Code suggestion
       @@ -1169,1 +1169,1 @@
      -            dataset_id=1, table_name="Test Dataset", schema="main"
      +            dataset_id=1, table_name="Test Dataset", schema="main",
Review Details
  • Files reviewed - 1 · Commit Range: 59446fa..59446fa
    • tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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 Default Agent 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 +1221 to +1222
# Verify the mock was called
mock_list.assert_called_once()
Copy link
Contributor

Choose a reason for hiding this comment

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

Incomplete test assertions for ordering parameters

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.

Code suggestion
Check the AI-generated fix before applying
Suggested change
# Verify the mock was called
mock_list.assert_called_once()
# 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"

Code Review Run #54e06e


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines +1221 to +1222
# Verify the mock was called
mock_list.assert_called_once()
Copy link
Contributor

Choose a reason for hiding this comment

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

Incomplete test assertions for default ordering

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.

Code suggestion
Check the AI-generated fix before applying
Suggested change
# Verify the mock was called
mock_list.assert_called_once()
# 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"

Code Review Run #54e06e


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.99%. Comparing base (76d897e) to head (6a384ed).
⚠️ Report is 2967 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #36279      +/-   ##
==========================================
+ Coverage   60.48%   67.99%   +7.50%     
==========================================
  Files        1931      636    -1295     
  Lines       76236    46817   -29419     
  Branches     8568     5081    -3487     
==========================================
- Hits        46114    31831   -14283     
+ Misses      28017    13710   -14307     
+ Partials     2105     1276     -829     
Flag Coverage Δ
hive 43.75% <ø> (-5.41%) ⬇️
javascript ?
mysql 67.09% <ø> (?)
postgres 67.14% <ø> (?)
presto 47.35% <ø> (-6.46%) ⬇️
python 67.95% <ø> (+4.45%) ⬆️
sqlite 66.76% <ø> (?)
unit 100.00% <ø> (+42.36%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant