fix: replace psycopg2 with psycopg3 in CI scripts #1597

Closed
xiaoxia wants to merge 3 commits from fix/psycopg2-to-psycopg3 into develop
Owner

问题

CI 脚本中使用了 import psycopg2 / psycopg2.connect(...),但 requirements-base.txt 安装的是 psycopg[binary]==3.2.2(psycopg3)。psycopg3 的 import 是 import psycopg,导致所有需要 PG 的 CI job 失败。

修复内容

将以下两个文件中的 psycopg2 引用替换为 psycopg(psycopg3):

scripts/ci/run_integration_tests.sh

  • 第 200 行:import psycopg2import psycopg
  • 第 201 行:psycopg2.connect(...)psycopg.connect(...)
  • 第 307 行:import psycopg2import psycopg
  • 第 308 行:psycopg2.connect(...)psycopg.connect(...)

scripts/ci/run_validate.sh

  • 第 412 行:import psycopg2import psycopg
  • 第 413 行:psycopg2.connect(...)psycopg.connect(...)
  • 第 434 行:import psycopg2import psycopg
  • 第 435 行:psycopg2.connect(...)psycopg.connect(...)

兼容性说明

psycopg3 的 connect() API 与 psycopg2 基本兼容,本修复涉及的 connect() + autocommit + cursor() + execute() 操作无需其他改动。

影响

修复后 PR #1594 的 CI(Validate - Python, Integration Tests 等)应能恢复正常。

## 问题 CI 脚本中使用了 `import psycopg2` / `psycopg2.connect(...)`,但 `requirements-base.txt` 安装的是 `psycopg[binary]==3.2.2`(psycopg3)。psycopg3 的 import 是 `import psycopg`,导致所有需要 PG 的 CI job 失败。 ## 修复内容 将以下两个文件中的 psycopg2 引用替换为 psycopg(psycopg3): ### `scripts/ci/run_integration_tests.sh` - 第 200 行:`import psycopg2` → `import psycopg` - 第 201 行:`psycopg2.connect(...)` → `psycopg.connect(...)` - 第 307 行:`import psycopg2` → `import psycopg` - 第 308 行:`psycopg2.connect(...)` → `psycopg.connect(...)` ### `scripts/ci/run_validate.sh` - 第 412 行:`import psycopg2` → `import psycopg` - 第 413 行:`psycopg2.connect(...)` → `psycopg.connect(...)` - 第 434 行:`import psycopg2` → `import psycopg` - 第 435 行:`psycopg2.connect(...)` → `psycopg.connect(...)` ## 兼容性说明 psycopg3 的 `connect()` API 与 psycopg2 基本兼容,本修复涉及的 `connect()` + `autocommit` + `cursor()` + `execute()` 操作无需其他改动。 ## 影响 修复后 PR #1594 的 CI(Validate - Python, Integration Tests 等)应能恢复正常。
xiaoxia added 2 commits 2026-09-01 08:14:44 +08:00
fix: replace psycopg2 with psycopg3 in run_validate.sh
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 4m7s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m28s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Failing after 4m37s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 5m0s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 6m11s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 6m15s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 6m17s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 7m29s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 7m40s
AI Code Review / AI Code Review (pull_request) Successful in 7m41s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 13m29s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Failing after 1s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
e61cb3abdb

🚀 预览环境已部署

项目 详情
PR号 #1597
预览链接 https://pr-1597.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1597 | | 预览链接 | [https://pr-1597.preview.xiaoxiajianji.com](https://pr-1597.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
xiaoxia added 1 commit 2026-09-01 10:21:44 +08:00
ci: trigger CI for psycopg2 fix verification
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Validate - Style (pull_request) Successful in 4m20s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 4m23s
AI Code Review / AI Code Review (pull_request) Successful in 4m30s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 5m2s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 5m30s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Failing after 5m33s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 7m20s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Successful in 9m13s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 9m33s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 10m22s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m29s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 24m11s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Failing after 3s
1f48ae6bc8
Collaborator

【阻塞级判定】

  • 是否存在阻塞级问题:否
  • 阻塞级问题数量:0 个

📊 审查概览

  • 整体评价:有建议
  • 建议级问题数量:2 个

🔴 阻塞级问题(必须修复)

💡 改进建议(不阻塞合并)

  1. [scripts/ci/run_integration_tests.sh, scripts/ci/run_validate.sh] 依赖环境确认

    • 具体内容:代码将数据库驱动从 psycopg2 迁移到了 psycopg (psycopg 3)。请确保 CI 运行环境的 Python 依赖中已安装 psycopg 库,否则脚本执行时会报 ModuleNotFoundError: No module named 'psycopg'
  2. [scripts/ci/run_integration_tests.sh: 348] 文件末尾换行符缺失

    • 具体内容:Diff 显示文件末尾添加注释后没有换行符(No newline at end of file)。虽然不影响脚本执行,但不符合 POSIX 文本文件标准(建议文本文件以 \n 结尾),建议在文件末尾添加一个空行。

良好实践

  • 将数据库驱动从 psycopg2 升级到 psycopg (v3) 是积极的代码现代化举措,有助于利用新库的性能提升和类型支持。

🤖 由 AI 代码审查机器人自动生成 | 2026-09-01 02:26:15 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:否 - 阻塞级问题数量:0 个 ### 📊 审查概览 - 整体评价:有建议 - 建议级问题数量:2 个 ### 🔴 阻塞级问题(必须修复) 无 ### 💡 改进建议(不阻塞合并) 1. **[scripts/ci/run_integration_tests.sh, scripts/ci/run_validate.sh] 依赖环境确认** - 具体内容:代码将数据库驱动从 `psycopg2` 迁移到了 `psycopg` (psycopg 3)。请确保 CI 运行环境的 Python 依赖中已安装 `psycopg` 库,否则脚本执行时会报 `ModuleNotFoundError: No module named 'psycopg'`。 2. **[scripts/ci/run_integration_tests.sh: 348] 文件末尾换行符缺失** - 具体内容:Diff 显示文件末尾添加注释后没有换行符(No newline at end of file)。虽然不影响脚本执行,但不符合 POSIX 文本文件标准(建议文本文件以 `\n` 结尾),建议在文件末尾添加一个空行。 ### ✅ 良好实践 - 将数据库驱动从 `psycopg2` 升级到 `psycopg` (v3) 是积极的代码现代化举措,有助于利用新库的性能提升和类型支持。 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-09-01 02:26:15 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia closed this pull request 2026-09-01 10:30:45 +08:00

🗑️ 预览环境已清理

PR #1597 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1597 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Some checks are pending
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Validate - Style (pull_request) Successful in 4m20s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 4m23s
AI Code Review / AI Code Review (pull_request) Successful in 4m30s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 5m2s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 5m30s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Failing after 5m33s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 7m20s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Successful in 9m13s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 9m33s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 10m22s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m29s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 24m11s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Failing after 3s

Pull request closed

Sign in to join this conversation.