[Refactor/Chore] use Testcontainers to do sql test #22261

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

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

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactors or chores; 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.

Description

now it's hard to do SQL improvement since all the query is patch.

Testcontainers will be much easier.

Motivation

Improve DX

Additional Context

Chat with llm https://g.co/gemini/share/abe5288b661a (chat is in Chinese).

Originally created by @asukaminato0721 on GitHub (Feb 21, 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 refactors or chores; 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. ### Description now it's hard to do SQL improvement since all the query is patch. Testcontainers will be much easier. ### Motivation Improve DX ### Additional Context Chat with llm https://g.co/gemini/share/abe5288b661a (chat is in Chinese).
Author
Owner

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

@dosu what is your opinion

@asukaminato0721 commented on GitHub (Feb 21, 2026): @dosu what is your opinion
Author
Owner

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

Good news—Dify has already adopted Testcontainers for database testing! The project has an established test_containers_integration_tests directory that spins up real PostgreSQL (postgres:14-alpine) containers for integration tests.

I fully agree with the motivation here. The patch-based approach had real limitations:

  • Environment inconsistencies between local and CI/CD
  • Flaky tests from shared database state
  • Mocks can't catch actual constraint violations or DB behavior quirks

There's active work to expand Testcontainers coverage across more service modules (workflow draft variable service, app DSL service, API extension service, etc.).

If you're looking to contribute, this might be more about expanding existing Testcontainers coverage rather than introducing the pattern from scratch. Are you interested in adding tests for a specific service or module?

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 21, 2026): <!-- Answer --> Good news—Dify has **already adopted Testcontainers** for database testing! The project has an established [test_containers_integration_tests directory](https://github.com/langgenius/dify/blob/8141e3af996c5ee4d2dd313f16ddc4c8854956e2/api/tests/test_containers_integration_tests/conftest.py) that spins up real PostgreSQL (postgres:14-alpine) containers for integration tests. I fully agree with the motivation here. The patch-based approach had real limitations: - Environment inconsistencies between local and CI/CD - Flaky tests from shared database state - Mocks can't catch actual constraint violations or DB behavior quirks There's [active work to expand Testcontainers coverage](https://github.com/langgenius/dify/issues/23268) across more service modules (workflow draft variable service, app DSL service, API extension service, etc.). If you're looking to contribute, this might be more about **expanding existing Testcontainers coverage** rather than introducing the pattern from scratch. Are you interested in adding tests for a specific service or module? <!-- 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/4e32fb58-ca9a-45d5-b608-7ba8762fa449?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/4e32fb58-ca9a-45d5-b608-7ba8762fa449?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/4e32fb58-ca9a-45d5-b608-7ba8762fa449?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/4e32fb58-ca9a-45d5-b608-7ba8762fa449?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4e32fb58-ca9a-45d5-b608-7ba8762fa449?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/4e32fb58-ca9a-45d5-b608-7ba8762fa449?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4e32fb58-ca9a-45d5-b608-7ba8762fa449?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=Good%20news%E2%80%94Dify%20has%20%2A%2Aalready%20adopted%20Testcontainers%2A%2A%20for%20database%20testing%21%20The%20project%20has%20an%20established%20%5Btest_containers_integration_tests%20directory%5D%28https%3A//github.com/langgenius/dify/blob/8141e3af996c5ee4d2dd313f16ddc4c8854956e2/api/tests/test_containers_integration_tests/conftest.py%29%20that%20spins%20up%20real%20PostgreSQL%20%28postgres%3A14-alpine%29%20containers%20for%20integration%20tests.%0A%0AI%20fully%20agree%20with%20the%20motivation%20here.%20The%20patch-based%20approach%20had%20real%20limitations%3A%0A-%20Environment%20inconsistencies%20between%20local%20and%20CI/CD%0A-%20Flaky%20tests%20from%20shared%20database%20state%0A-%20Mocks%20can%27t%20catch%20actual%20constraint%20violations%20or%20DB%20behavior%20quirks%0A%0AThere%27s%20%5Bactive%20work%20to%20expand%20Testcontainers%20coverage%5D%28https%3A//github.com/langgenius/dify/issues/23268%29%20across%20more%20service%20modules%20%28workflow%20draft%20variable%20service%2C%20app%20DSL%20service%2C%20API%20extension%20service%2C%20etc.%29.%0A%0AIf%20you%27re%20looking%20to%20contribute%2C%20this%20might%20be%20more%20about%20%2A%2Aexpanding%20existing%20Testcontainers%20coverage%2A%2A%20rather%20than%20introducing%20the%20pattern%20from%20scratch.%20Are%20you%20interested%20in%20adding%20tests%20for%20a%20specific%20service%20or%20module%3F)&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/32454)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#22261