Skip to content

Commit a57b61a

Browse files
committed
Fix broken failure handling
* Correctly fail files with bad headers * Streamline files with bad rows: fail without needing to hit the database
1 parent e56dca2 commit a57b61a

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/acquisition/covidcast/csv_to_database.py

+14-18
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,23 @@ def archive_as_successful(path_src, filename, source):
7474

7575
(source, signal, time_type, geo_type, time_value, issue, lag) = details
7676

77-
is_wip = False
78-
if signal[:4].lower() == "wip_":
79-
is_wip = True
80-
print(signal, is_wip)
77+
is_wip = signal[:4].lower() == "wip_"
8178

8279
csv_rows = csv_importer_impl.load_csv(path, geo_type)
8380

84-
all_rows_valid = False
85-
try:
86-
cc_rows = CovidcastRow.fromCsvRows(csv_rows, source, signal, time_type, geo_type, time_value, issue, lag, is_wip)
87-
rows_list = list(cc_rows)
88-
if not rows_list:
89-
raise ValueError("No data")
90-
result = database.insert_or_update_bulk(rows_list)
91-
if result is None or result: # else would indicate zero rows inserted
92-
database.commit()
93-
all_rows_valid = True
94-
except Exception as e:
95-
all_rows_valid = False
96-
print('exception while inserting rows:', e)
97-
database.rollback()
81+
cc_rows = CovidcastRow.fromCsvRows(csv_rows, source, signal, time_type, geo_type, time_value, issue, lag, is_wip)
82+
rows_list = list(cc_rows)
83+
all_rows_valid = rows_list and all(r is not None for r in rows_list)
84+
if all_rows_valid:
85+
try:
86+
result = database.insert_or_update_bulk(rows_list)
87+
print(f"insert_or_update_bulk {filename} returned {result}")
88+
if result is None or result: # else would indicate zero rows inserted
89+
database.commit()
90+
except Exception as e:
91+
all_rows_valid = False
92+
print('exception while inserting rows:', e)
93+
database.rollback()
9894

9995
# archive the current file based on validation results
10096
if all_rows_valid:

src/acquisition/covidcast/database.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CovidcastRow():
1919

2020
@staticmethod
2121
def fromCsvRowValue(row_value, source, signal, time_type, geo_type, time_value, issue, lag, is_wip):
22+
if row_value is None: return None
2223
return CovidcastRow(source, signal, time_type, geo_type, time_value,
2324
row_value.geo_value,
2425
row_value.value,

0 commit comments

Comments
 (0)