Skip to content

[Bug]: Python config parses invalid environment values despite explicit overrides #31312

Description

@MatrixAdventurer

由 LW 授权的 ChatGPT Agent 操作。

Is there an existing issue for the same bug?

  • I have checked the existing issues.
    Searched configuration/environment override issues and open PRs; no matching fix found.

Branch Name

main

Commit ID

24c1ac8

Other Environment Information

Linux, Python 3.12.14, SQLAlchemy 2.0.55. This reproduces before any database connection.

Actual Behavior

An invalid MATRIXONE_PORT or MATRIXONE_CONNECT_TIMEOUT is converted with int() before explicit keyword overrides are applied. A valid explicit override therefore still raises ValueError.

Expected Behavior

The documented order is explicit parameters > environment > defaults. An overridden environment value must not be parsed. Invalid environment values without an override must still be rejected.

Steps to Reproduce

import os
from matrixone.config import get_connection_kwargs
os.environ["MATRIXONE_PORT"] = "invalid"
get_connection_kwargs(port=6002)

Actual: ValueError: invalid literal for int() with base 10: 'invalid'
Expected: configuration with port=6002. The timeout field fails in the same way.

Additional information

Fix: skip environment lookup for keys present in explicit overrides, retaining the existing final update and conversion behavior for remaining fields.
Regression: 5 failed / 3 passed before the fix; all 8 pass afterward. Public config, connection kwargs and tuple outputs are covered, including zero/false/empty values and invalid unoverridden settings.
Complete offline SDK suite: 1962 passed plus 95 subtests. CI fatal flake8 selection, new-test lint and git diff --check pass. Two files, +79 lines, of which two are production lines.
No live SQL BVT is needed for this local configuration-selection contract: the operation ends at a configuration dictionary/tuple and no transport, SQL, server or persistence behavior changes. Hosted CI is not yet verified.

Activity

  1. added a commit that references this issue on Oct 27, 2026
    baa83f4
  2. XuPeng-SH commented on Oct 27, 2026

    @XuPeng-SH
    Contributor

    QA on merged SDK source baa83f4b96e56ec214f92c68f7b56539b9e0fa45: the complete offline suite passed (2,279 tests plus 95 subtests) with Python 3.12.14 / SQLAlchemy 2.0.55. Its eight test_config_precedence.py cases verify explicit port/timeout overrides against invalid environment values, zero and connection outputs, rejection of unoverridden invalid values, and environment/default controls. This covers the reported local configuration-selection contract; no server is required for that contract. Hosted CI was not verified by this run. Assignment remains unchanged pending handoff.

  3. Ariznawlll commented on Oct 27, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • main:d4ffbae43d55da21526eab01722cbef14bb01ed5;修复 PR #31322 的 merge commit baa83f4b96e56ec214f92c68f7b56539b9e0fa45 在该提交祖先链中。
    • 2026-10-27,macOS/arm64,Python 3.14.3、SQLAlchemy 2.1.6;配置选择测试不连接数据库。MOTR 场景另外连接同一 commit 的隔离 1 CN + 1 TN + 1 LogService。

    原问题验证

    分别把端口及连接超时环境值设置为非法字符串,同时显式传入端口 6002、超时 7;公开配置入口实际返回 6002 和 7,不会解析被覆盖的非法值。定向 SDK 测试与 MOTR 场景各独立重复 3 次,均通过。

    Happy Path 覆盖

    验证 get_config、get_connection_kwargs、get_client_kwargs 及 tuple 入口;正常环境值被转换,显式 0、False、空字符串与 None 按提供值处理,未覆盖字段仍按环境或默认值解析。配置输出隐藏密码,默认配置不因调用而改变。

    Unhappy Path 覆盖

    端口或超时没有显式覆盖且环境值非法时仍抛出 ValueError;验证未选择的无效环境项不会被读取。测试后恢复进程环境变量。

    白盒验证

    本问题为 Python 配置选择,未涉及 Go 路径,无 Go race;独立运行 tests/offline/contracts/test_config_result_boundaries.py 和全文分页参数化测试,合计 58 项,3 轮均通过。

    回归测试

    MOTR #284 增加 SDK 公共入口场景;该场景与相邻 #30824 用例各运行 3 次、均通过。未运行完整 MOTR 套件。

    测试证据

    修复 PR 的 Python SDK 离线 CI 矩阵通过,online job 标记 skipped;MOTR 新 head 的四项托管离线检查通过,不把离线检查等同完整在线 CI。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions