已开启
feat: add mysql-connector-python compatibility test for openGauss dolphin plugin #107
feat: add mysql-connector-python compatibility test for openGauss dolphin plugin #107
已开启
liuhaodong-2026创建于 24 天前
24 天前

【标题】Add mysql-connector-python compatibility test for openGauss dolphin plugin

【实现内容】:
新增 mysql-connector-python 连接 openGauss B 兼容模式数据库的兼容性测试代码及自测报告,位于 MysqlConnectorCompatibility/ 目录。

【根因分析】:
现有 examples 仓库缺少 mysql-connector-python 驱动的兼容性验证,开发者无法了解该驱动连接 openGauss dolphin 插件的可行性及所需配置。

【实现方案】:
编写覆盖 18 个测试场景的测试脚本,发现并记录 3 个兼容性问题(collation 不支持、C 扩展认证失败、反斜杠转义不兼容),提供解决方案,全部测试通过(18/18)。

【关联需求或issue】: /

【开发自验报告】:

  1. 已在 openGauss 7.0.0-RC3 + dolphin 插件环境验证,18 项测试全部通过,详见 self_test_report_connector.md。
  2. 不涉及 fastcheck 测试用例。
  3. 涉及资料修改,已在 docs 仓库补充开发指导文档(单独 PR)。
  4. 不涉及升级场景。
  5. 不涉及在线扩容等扩展场景。
  6. 不涉及异常/并发/前向兼容/性能场景。
  7. 不对其他模块产生影响。
  8. 不需要回合补丁版本。
  9. 不涉及 DOLPHIN 宏。

【当前PR是否有AI参与】:
[x] 否

likedislike
合并受阻
Lliuhaodong-2026
24 天前 创建了 pull request,commit d9de07bb
opengauss_botopengauss_bot成员
24 天前 添加了label:sig/Infra
opengauss_bot
opengauss_bot成员
24 天前 评论:

Welcome To openGauss Community

Hey @liuhaodong-2026 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: Infra ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @ailoooong, @gzbang, @libiao2024, @zhangxubo .

likedislike
opengauss_botopengauss_bot成员
24 天前 添加了label:stat/needs-squash
opengauss_botopengauss_bot成员
24 天前 添加了label:opengauss-cla/yes
Lliuhaodong-2026
23 天前 修改了pull request 的描述
opengauss_botopengauss_bot成员
23 天前 添加了label:ai-co-authored
opengauss_botopengauss_bot成员
23 天前 添加了label:ai-includes-code
opengauss_bot
opengauss_bot成员
23 天前 评论:

AI Declaration Check Failed

@liuhaodong-2026, AI declaration compliance check failed, please try again later. ❌

likedislike
Lliuhaodong-2026
16 天前 修改了pull request 的描述
opengauss_botopengauss_bot成员
16 天前 删除了label:ai-co-authoredai-includes-code
wofanzheng
wofanzheng成员4 天前进行代码检视3
MysqlConnectorCompatibility/test_connector_opengauss.py
@@ -0,0 +47,4 @@
47+ return True
48+ except Exception as e:
49+ print(f" FAIL {name}: {e}")
50+ return False
wofanzheng
wofanzheng4 天前评论:

【问题】
异常只被转换成 False,最终没有返回非零退出码,测试失败时 CI 仍可能判断成功。

【建议】
末尾增加:
raise SystemExit(1 if failed else 0)

likedislike
wofanzheng
wofanzheng成员
3 天前 评论:

复核当前 head 288fd2af:主程序仍只打印 failed 数量,没有返回非零退出码;任一用例失败时进程仍会以 0 退出,CI 仍可能误判通过。本条尚未修改,请在结果输出后执行 raise SystemExit(1 if failed else 0)。

liuhaodong-2026
1 天前 评论:

已修复,请复核。退出码:脚本末尾加 raise SystemExit(1 if failed else 0),CI 现在能正确感知测试失败。

wofanzheng
wofanzheng成员4 天前进行代码检视3
MysqlConnectorCompatibility/test_connector_opengauss.py
@@ -0,0 +333,4 @@
333+ 
334+ try:
335+ cur.execute("INSERT INTO nonexistent_table VALUES (1)")
336+ except ce.ProgrammingError:
wofanzheng
wofanzheng4 天前评论:

【问题】
报错后未 rollback,342行 开始的重复键测试可能运行在 aborted transaction 中;同时代码捕获任意异常且没有断言,导致错误映射不正确时仍然 PASS。、

【建议】
两个错误场景使用独立事务;第一个错误后立即 rollback,并断言准确异常类型或 SQLSTATE。

likedislike
wofanzheng
wofanzheng成员
3 天前 评论:

复核当前 head 288fd2af:第一个错误后仍未 rollback,重复键场景仍可能在 aborted transaction 中执行;两处仍捕获任意异常且不校验异常类型、错误码或 SQLSTATE,因此错误映射不正确时仍会 PASS。本条尚未修改。请将两个错误场景拆为独立事务或连接,并分别断言预期异常;重复键必须断言 IntegrityError、1062/23000,不能把任意异常作为通过。

liuhaodong-2026
1 天前 评论:

已修复,请复核 事务缺少 rollback:test_error_mapping() 中 table_not_found 异常捕获后补充 conn.rollback(),避免后续 dup_key 测试在 aborted transaction 中运行。

wofanzheng
wofanzheng成员4 天前进行代码检视4
MysqlConnectorCompatibility/test_connector_opengauss.py
已过期
@@ -0,0 +228,4 @@
228+ cur = conn.cursor()
229+ cur.execute("DROP TABLE IF EXISTS t_blob")
230+ cur.execute("CREATE TABLE t_blob (id INT PRIMARY KEY, data BLOB)")
231+ cur.execute("INSERT INTO t_blob VALUES (1, X'')")
wofanzheng
wofanzheng4 天前评论:

【问题】
测试使用 X'...' SQL 字面量,没有绑定 Python bytes,并且只比较长度。即使 bytes 参数不支持或内容损坏,测试仍可能 PASS。

【建议】
通过 %s 绑定 bytes,查询原始列并逐字节比较。

likedislike
wofanzheng
wofanzheng成员
3 天前 评论:

复核当前 head 288fd2af:BLOB 用例仍使用 X 十六进制 SQL 字面量,只比较长度,未覆盖 mysql-connector 对 Python bytes 的参数编码,也不能证明内容未损坏。本条尚未修改。请用 %s 绑定空 bytes、含 0x00/0xFF 的 bytes 和 1 KB bytes,查询 data 原列并逐字节断言相等。

System
系统消息系统
1 天前 评论:

changed this line on da86edb4 view diff detail

liuhaodong-2026
1 天前 评论:

已修复,请复核 BLOB 测试只验证长度:test_binary_blob() 改为用 %s 绑定 Python bytes 插入,SELECT 后逐字节比较实际内容,而非只比较 LENGTH(data)。

wofanzheng
wofanzheng成员3 天前进行代码检视2
MysqlConnectorCompatibility/test_connector_opengauss.py
@@ -0,0 +29,4 @@
29+CHARSET = "utf8mb4"
30+ 
31+ 
32+def new_conn(**kwargs):
wofanzheng
wofanzheng3 天前评论:

【问题】公共连接方法仍未配置 sql_mode="NO_BACKSLASH_ESCAPES";普通 CRUD 数据恰好没有引号或反斜杠,无法发现通用连接在真实特殊字符下的编码问题。只在个别测试中连接后执行原始 SET,还可能与 Connector/Python 缓存的 connection.sql_mode 不一致。

【建议】在 mysql.connector.connect() 参数中直接增加 sql_mode="NO_BACKSLASH_ESCAPES",并在普通 CRUD 增加含单引号和反斜杠的参数绑定、逐值往返断言。

likedislike
liuhaodong-2026
1 天前 评论:

已修复,请复核 sql_mode 未全局配置:new_conn() 的 mysql.connector.connect() 参数中加入 sql_mode="NO_BACKSLASH_ESCAPES",删除各测试函数里零散的临时 SET sql_mode;并在 test_crud() 中补充了一条含单引号+反斜杠的普通 CRUD 用例("O'Brien\Corp"),验证连接级配置下常规写入也是安全的。

Lliuhaodong-2026
1 天前 update merge request[project id: 5089494, iid: 107, commit_id: c967c3666ad42dc57a54bf045662c0f43bb97b9a] virtual merging success
此处折叠了8条事件消息 查看更多
opengauss_botopengauss_bot成员
1 天前 添加了label:opengauss-cla/yes
opengauss_bot
opengauss_bot成员
1 天前 评论:

CLA Signature Pass

liuhaodong-2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike