dify - ✅(Solved) Fix fix the test failed [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langgenius/dify#36133Fetched 2026-05-14 03:46:30
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
1
Author
Participants
Timeline (top)
closed ×1cross-referenced ×1labeled ×1

Error Message

def test_sse_message_id_coercion(): """Test that string message IDs that look like integers are parsed as integers.

    See <https://github.com/modelcontextprotocol/python-sdk/pull/851> for more details.
    """
    json_message = '{"jsonrpc": "2.0", "id": "123", "method": "ping", "params": null}'
    msg = types.JSONRPCMessage.model_validate_json(json_message)
    expected = types.JSONRPCMessage(root=types.JSONRPCRequest(method="ping", jsonrpc="2.0", id=123))

    # Check if both are JSONRPCRequest instances
  assert isinstance(msg.root, types.JSONRPCRequest)

E AssertionError: assert False E + where False = isinstance(JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123'), <class 'core.mcp.types.JSONRPCRequest'>) E + where JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123') = JSONRPCMessage(root=JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123')).root E + and <class 'core.mcp.types.JSONRPCRequest'> = types.JSONRPCRequest

Fix Action

Fixed

PR fix notes

PR #36134: fix: fix pydantic union type error

Description (problem / solution / changelog)

[!IMPORTANT]

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fix #36133

Screenshots

BeforeAfter
......

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

Changed files

  • api/core/mcp/types.py (modified, +16/-2)
  • api/tests/unit_tests/core/mcp/client/test_sse.py (modified, +11/-0)

Code Example

def test_sse_message_id_coercion():
        """Test that string message IDs that look like integers are parsed as integers.
    
        See <https://github.com/modelcontextprotocol/python-sdk/pull/851> for more details.
        """
        json_message = '{"jsonrpc": "2.0", "id": "123", "method": "ping", "params": null}'
        msg = types.JSONRPCMessage.model_validate_json(json_message)
        expected = types.JSONRPCMessage(root=types.JSONRPCRequest(method="ping", jsonrpc="2.0", id=123))
    
        # Check if both are JSONRPCRequest instances
>       assert isinstance(msg.root, types.JSONRPCRequest)
E       AssertionError: assert False
E        +  where False = isinstance(JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123'), <class 'core.mcp.types.JSONRPCRequest'>)
E        +    where JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123') = JSONRPCMessage(root=JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123')).root
E        +    and   <class 'core.mcp.types.JSONRPCRequest'> = types.JSONRPCRequest
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

def test_sse_message_id_coercion():
        """Test that string message IDs that look like integers are parsed as integers.
    
        See <https://github.com/modelcontextprotocol/python-sdk/pull/851> for more details.
        """
        json_message = '{"jsonrpc": "2.0", "id": "123", "method": "ping", "params": null}'
        msg = types.JSONRPCMessage.model_validate_json(json_message)
        expected = types.JSONRPCMessage(root=types.JSONRPCRequest(method="ping", jsonrpc="2.0", id=123))
    
        # Check if both are JSONRPCRequest instances
>       assert isinstance(msg.root, types.JSONRPCRequest)
E       AssertionError: assert False
E        +  where False = isinstance(JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123'), <class 'core.mcp.types.JSONRPCRequest'>)
E        +    where JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123') = JSONRPCMessage(root=JSONRPCNotification(method='ping', params=None, jsonrpc='2.0', id='123')).root
E        +    and   <class 'core.mcp.types.JSONRPCRequest'> = types.JSONRPCRequest

it can be basically determined that this is an issue arising from changes in Pydantic v2's union type matching behavior. But more precisely, it's the result of these factors (stacking together):

  • JSONRPCMessage is a plain union: JSONRPCRequest | JSONRPCNotification | JSONRPCResponse | JSONRPCError
  • JSONRPCNotification has extra="allow" enabled, so although it doesn't declare an id field, it can still accept input like {"id": "123", "method": "ping"}.
  • id="123" in JSONRPCRequest goes through RequestId = Annotated[int | str, Field(union_mode="left_to_right")] and gets coerced into 123.
  • Newer versions of Pydantic prefer the union branch that is more precise / involves less coercion, so it may ultimately classify the input as JSONRPCNotification instead of JSONRPCRequest.

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING