Skip to content

Commit ab41fa0

Browse files
committed
warn on unexpected or missing keys and fill in
1 parent c88c6fc commit ab41fa0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/acquisition/flusurv/flusurv_update.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,22 @@ def update(fetcher, location, test_mode=False):
148148
# Remove the season description since we also store it in each epiweek obj
149149
unexpected_groups = data[epiweek].keys() - EXPECTED_GROUPS - {"season"}
150150
if len(missing_expected_groups) != 0:
151-
raise ValueError(
151+
warn(
152152
f"{location} {epiweek} data is missing group(s) {missing_expected_groups}"
153153
)
154+
# Fill in expected values with `None` so SQL query injection below
155+
# doesn't fail with a key error.
156+
for key in missing_expected_groups:
157+
data[epiweek][key] = None
154158
if len(unexpected_groups) != 0:
155-
raise ValueError(
159+
warn(
156160
f"{location} {epiweek} data includes new group(s) {unexpected_groups}"
157161
)
162+
# Remove unexpected values from the data. Construction of the SQL
163+
# query below fetches values by key, so these would be ignored even
164+
# if we left them.
165+
for key in unexpected_groups:
166+
del data[epiweek][key]
158167

159168
args_meta = {
160169
"release_date": release_date,

0 commit comments

Comments
 (0)