fix: correctly detect required columns in archived workflow run restore (#33403)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
非法操作
2026-03-13 23:24:40 +08:00
committed by GitHub
parent 194c205ed3
commit 573b4e41cb
2 changed files with 116 additions and 21 deletions

View File

@ -358,21 +358,19 @@ class WorkflowRunRestore:
self,
model: type[DeclarativeBase] | Any,
) -> tuple[set[str], set[str], set[str]]:
columns = list(model.__table__.columns)
table = model.__table__
columns = list(table.columns)
autoincrement_column = getattr(table, "autoincrement_column", None)
def has_insert_default(column: Any) -> bool:
# SQLAlchemy may set column.autoincrement to "auto" on non-PK columns.
# Only treat the resolved autoincrement column as DB-generated.
return column.default is not None or column.server_default is not None or column is autoincrement_column
column_names = {column.key for column in columns}
required_columns = {
column.key
for column in columns
if not column.nullable
and column.default is None
and column.server_default is None
and not column.autoincrement
}
required_columns = {column.key for column in columns if not column.nullable and not has_insert_default(column)}
non_nullable_with_default = {
column.key
for column in columns
if not column.nullable
and (column.default is not None or column.server_default is not None or column.autoincrement)
column.key for column in columns if not column.nullable and has_insert_default(column)
}
return column_names, required_columns, non_nullable_with_default