微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
@@ -20,7 +20,15 @@ class DatabaseConnection:
|
||||
# 生产环境要求:数据库连接超时不得超过 20 秒。
|
||||
timeout_val = max(1, min(int(timeout_val), 20))
|
||||
|
||||
conn = psycopg2.connect(self._dsn, connect_timeout=timeout_val)
|
||||
# CHANGE 2026-03-06 | intent: 修复 Windows GBK 环境下 psycopg2 连接握手的 UnicodeDecodeError
|
||||
# assumptions: libpq 默认使用系统 locale 的 client_encoding,Windows 中文系统为 GBK/CP936
|
||||
# 边界: 显式指定 client_encoding=utf8 确保连接层始终使用 UTF-8,与数据库 server_encoding 一致
|
||||
# 验证: web-admin 手动触发 ETL 全量 flow,不再出现 0xd6 解码错误
|
||||
conn = psycopg2.connect(
|
||||
self._dsn,
|
||||
connect_timeout=timeout_val,
|
||||
options="-c client_encoding=utf8",
|
||||
)
|
||||
conn.autocommit = False
|
||||
|
||||
# 会话参数(时区、语句超时等)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""数据库批量操作"""
|
||||
"""数据库批量操作
|
||||
|
||||
AI_CHANGELOG
|
||||
- 2026-03-06 09:17:16 | Prompt: P20260306-084752(摘录:DWD 并行装载全部失败 _dsn 属性缺失)| Direct cause:DatabaseOperations 组合模式未透传 _dsn/_session/_connect_timeout | Summary:新增 3 个 property 透传底层 DatabaseConnection 属性 | Verify:334 单元测试通过 + getDiagnostics 无问题
|
||||
"""
|
||||
import psycopg2.extras
|
||||
import re
|
||||
|
||||
@@ -9,6 +13,23 @@ class DatabaseOperations:
|
||||
def __init__(self, connection):
|
||||
self._connection = connection
|
||||
self.conn = connection.conn
|
||||
|
||||
# [CHANGE P20260306-084752] intent: 透传底层 DatabaseConnection 的连接参数,
|
||||
# DwdLoadTask._process_single_table 需要 _dsn/_session/_connect_timeout
|
||||
# 为每个线程创建独立连接
|
||||
# assumptions: _connection 始终是 DatabaseConnection 实例,具有这三个属性
|
||||
# verify: 334 单元测试通过,DWD 并行装载不再 AttributeError
|
||||
@property
|
||||
def _dsn(self):
|
||||
return self._connection._dsn
|
||||
|
||||
@property
|
||||
def _session(self):
|
||||
return self._connection._session
|
||||
|
||||
@property
|
||||
def _connect_timeout(self):
|
||||
return self._connection._connect_timeout
|
||||
|
||||
def batch_execute(self, sql: str, rows: list, page_size: int = 1000):
|
||||
"""批量执行SQL"""
|
||||
|
||||
Reference in New Issue
Block a user