Skip to content

Commit 2cd489c

Browse files
fix(clp-json): Explicitly specify what fields to update in update_archive_metadata (fixes #1039). (#1043)
Co-authored-by: kirkrodrigues <[email protected]>
1 parent f2deb21 commit 2cd489c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

components/job-orchestration/job_orchestration/executor/compress/compression_task.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,33 @@ def update_job_metadata_and_tags(db_cursor, job_id, table_prefix, tag_ids, archi
9292

9393

9494
def update_archive_metadata(db_cursor, table_prefix, archive_stats):
95-
archive_stats_defaults = {
96-
"begin_timestamp": 0,
97-
"end_timestamp": 0,
98-
"creator_id": "",
95+
stats_to_update = {
96+
# Use defaults for values clp-s doesn't output
9997
"creation_ix": 0,
98+
"creator_id": "",
10099
}
101-
for k, v in archive_stats_defaults.items():
102-
archive_stats.setdefault(k, v)
103-
keys = ", ".join(archive_stats.keys())
104-
value_placeholders = ", ".join(["%s"] * len(archive_stats))
100+
101+
# Validate clp-s doesn't output the set kv-pairs
102+
for key in stats_to_update:
103+
if key in archive_stats:
104+
raise ValueError(f"Unexpected key '{key}' in archive stats")
105+
106+
required_stat_names = [
107+
"begin_timestamp",
108+
"end_timestamp",
109+
"id",
110+
"size",
111+
"uncompressed_size",
112+
]
113+
for stat_name in required_stat_names:
114+
stats_to_update[stat_name] = archive_stats[stat_name]
115+
116+
keys = ", ".join(stats_to_update.keys())
117+
value_placeholders = ", ".join(["%s"] * len(stats_to_update))
105118
query = (
106119
f"INSERT INTO {table_prefix}{ARCHIVES_TABLE_SUFFIX} ({keys}) VALUES ({value_placeholders})"
107120
)
108-
db_cursor.execute(query, list(archive_stats.values()))
121+
db_cursor.execute(query, list(stats_to_update.values()))
109122

110123

111124
def _generate_fs_logs_list(

0 commit comments

Comments
 (0)