test has different return type #22036

Open
opened 2026-02-21 20:15:23 -05:00 by yindo · 2 comments
Owner

Originally created by @asukaminato0721 on GitHub (Feb 3, 2026).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • 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.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

master

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

from extensions.ext_code_based_extension import code_based_extension


class CodeBasedExtensionService:
    @staticmethod
    def get_code_based_extension(module: str):
        module_extensions = code_based_extension.module_extensions(module)
        return [
            {
                "name": module_extension.name,
                "label": module_extension.label,
                "form_schema": module_extension.form_schema,
            }
            for module_extension in module_extensions
            if not module_extension.builtin
        ]

this is the function def, so it returns list[dict]

but in the test

def test_code_based_extension_get_returns_service_data(app: Flask, monkeypatch: pytest.MonkeyPatch):
    service_result = {"entrypoint": "main:agent"}
    service_mock = MagicMock(return_value=service_result)
    monkeypatch.setattr(
        "controllers.console.extension.CodeBasedExtensionService.get_code_based_extension",
        service_mock,
    )

    with app.test_request_context(
        "/console/api/code-based-extension",
        method="GET",
        query_string={"module": "workflow.tools"},
    ):
        response = CodeBasedExtensionAPI().get()

    assert response == {"module": "workflow.tools", "data": service_result}
    service_mock.assert_called_once_with("workflow.tools")

the service result has wrong type

related pr https://github.com/langgenius/dify/pull/31859

✔️ Expected Behavior

not err

Actual Behavior

No response

Originally created by @asukaminato0721 on GitHub (Feb 3, 2026). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version master ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce ```py from extensions.ext_code_based_extension import code_based_extension class CodeBasedExtensionService: @staticmethod def get_code_based_extension(module: str): module_extensions = code_based_extension.module_extensions(module) return [ { "name": module_extension.name, "label": module_extension.label, "form_schema": module_extension.form_schema, } for module_extension in module_extensions if not module_extension.builtin ] ``` this is the function def, so it returns list[dict] but in the test ```py def test_code_based_extension_get_returns_service_data(app: Flask, monkeypatch: pytest.MonkeyPatch): service_result = {"entrypoint": "main:agent"} service_mock = MagicMock(return_value=service_result) monkeypatch.setattr( "controllers.console.extension.CodeBasedExtensionService.get_code_based_extension", service_mock, ) with app.test_request_context( "/console/api/code-based-extension", method="GET", query_string={"module": "workflow.tools"}, ): response = CodeBasedExtensionAPI().get() assert response == {"module": "workflow.tools", "data": service_result} service_mock.assert_called_once_with("workflow.tools") ``` the service result has wrong type related pr https://github.com/langgenius/dify/pull/31859 ### ✔️ Expected Behavior not err ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 20:15:23 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 3, 2026):

The root cause of the error is that CodeBasedExtensionService.get_code_based_extension returns a list of dicts, but the test mocks it to return a dict instead, causing a type mismatch. To fix this, update the test so that the mock returns a list of dicts matching the real function's return type—for example, something like:

service_result = [
    {"name": "example", "label": "Example", "form_schema": {}}
]

and adjust the assertion accordingly. This will align the test with the actual implementation and resolve the error. For more context, see the implementation and test code here and here. This issue is also tracked in #31864.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 3, 2026): <!-- Answer --> The root cause of the error is that CodeBasedExtensionService.get_code_based_extension returns a list of dicts, but the test mocks it to return a dict instead, causing a type mismatch. To fix this, update the test so that the mock returns a list of dicts matching the real function's return type—for example, something like: ```python service_result = [ {"name": "example", "label": "Example", "form_schema": {}} ] ``` and adjust the assertion accordingly. This will align the test with the actual implementation and resolve the error. For more context, see the implementation and test code [here](https://github.com/langgenius/dify/blob/ebca36ffbbe119577ebabc28733e4e9875ec6993/api/services/code_based_extension_service.py#L4-L16) and [here](https://github.com/langgenius/dify/blob/ebca36ffbbe119577ebabc28733e4e9875ec6993/api/tests/unit_tests/controllers/console/test_extension.py#L79-L237). This issue is also tracked in [#31864](https://github.com/langgenius/dify/issues/31864). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/d9b39f6b-143d-4c8b-b6b5-fb11a388006a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/d9b39f6b-143d-4c8b-b6b5-fb11a388006a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/d9b39f6b-143d-4c8b-b6b5-fb11a388006a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/d9b39f6b-143d-4c8b-b6b5-fb11a388006a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d9b39f6b-143d-4c8b-b6b5-fb11a388006a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/d9b39f6b-143d-4c8b-b6b5-fb11a388006a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/d9b39f6b-143d-4c8b-b6b5-fb11a388006a?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20root%20cause%20of%20the%20error%20is%20that%20CodeBasedExtensionService.get_code_based_extension%20returns%20a%20list%20of%20dicts%2C%20but%20the%20test%20mocks%20it%20to%20return%20a%20dict%20instead%2C%20causing%20a%20type%20mismatch.%20To%20fix%20this%2C%20update%20the%20test%20so%20that%20the%20mock%20returns%20a%20list%20of%20dicts%20matching%20the%20real%20function%27s%20return%20type%E2%80%94for%20example%2C%20something%20like%3A%0A%0A%60%60%60python%0Aservice_result%20%3D%20%5B%0A%20%20%20%20%7B%22name%22%3A%20%22example%22%2C%20%22label%22%3A%20%22Example%22%2C%20%22form_schema%22%3A%20%7B%7D%7D%0A%5D%0A%60%60%60%0A%0Aand%20adjust%20the%20assertion%20accordingly.%20This%20will%20align%20the%20test%20with%20the%20actual%20implementation%20and%20resolve%20the%20error.%20For%20more%20context%2C%20see%20the%20implementation%20and%20test%20code%20%5Bhere%5D%28https%3A//github.com/langgenius/dify/blob/ebca36ffbbe119577ebabc28733e4e9875ec6993/api/services/code_based_extension_service.py%23L4-L16%29%20and%20%5Bhere%5D%28https%3A//github.com/langgenius/dify/blob/ebca36ffbbe119577ebabc28733e4e9875ec6993/api/tests/unit_tests/controllers/console/test_extension.py%23L79-L237%29.%20This%20issue%20is%20also%20tracked%20in%20%5B%2331864%5D%28https%3A//github.com/langgenius/dify/issues/31864%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/31864)
Author
Owner

@asukaminato0721 commented on GitHub (Feb 5, 2026):

cc @laipz8200 do I need to update the test?

@asukaminato0721 commented on GitHub (Feb 5, 2026): cc @laipz8200 do I need to update the test?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#22036