fix: 移除迁移数据中的 NUL 字符并记录警告

This commit is contained in:
Windpicker-owo
2025-11-27 23:18:05 +08:00
parent 8287d11c49
commit 86e04638a2

View File

@@ -400,9 +400,18 @@ def migrate_table_data(
error_count += len(rows)
batch: list[dict] = []
null_char_replacements = 0
for row in result:
# Use column objects to access row mapping to avoid quoted_name keys
row_dict = {col.key: row._mapping[col] for col in source_table.columns}
row_dict = {}
for col in source_table.columns:
val = row._mapping[col]
if isinstance(val, str) and "\x00" in val:
val = val.replace("\x00", "")
null_char_replacements += 1
row_dict[col.key] = val
batch.append(row_dict)
if len(batch) >= batch_size:
insert_batch(batch)
@@ -417,6 +426,12 @@ def migrate_table_data(
migrated_rows,
error_count,
)
if null_char_replacements:
logger.warning(
"%s%d 个字符串值包含 NUL 已被移除后写入目标库",
source_table.name,
null_char_replacements,
)
return migrated_rows, error_count