fix(error-handling): catch UnboundLocalError on update
Some checks are pending
Docker / build (push) Waiting to run

Ensure robustness in `update_database` by catching and handling `UnboundLocalError` to avoid potential crashes during data processing. This change mitigates risks where an uninitialized variable might lead to exceptions, thus enhancing application stability. Also includes minor whitespace corrections for improved code readability.
This commit is contained in:
Kumi 2024-11-13 16:17:46 +01:00
parent e7864eeaa1
commit 250061876c
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -405,7 +405,7 @@ def update_dominance(data):
if date_aux < date_aux2:
values_mat[k][1] = dominance.dominance
values_mat[k][0] = dominance.date
df.iloc[start_row:end_row, start_col:end_col] = values_mat
df.to_excel(DATA_FILE, sheet_name="Sheet7", index=False)
@ -442,7 +442,7 @@ def update_rank(data=None):
if date_aux < date_aux2:
values_mat[k][1] = rank.rank
values_mat[k][0] = rank.date
df.iloc[start_row:end_row, start_col:end_col] = values_mat
df.to_excel(DATA_FILE, sheet_name="Sheet8", index=False)
@ -783,7 +783,7 @@ def update_database(date_from=None, date_to=None):
data.crypto_subscriberCount = social_crypto.subscriberCount
data.crypto_commentsPerHour = social_crypto.commentsPerHour
data.crypto_postsPerHour = social_crypto.postsPerHour
except Social.DoesNotExist:
except (Social.DoesNotExist, UnboundLocalError):
data.btc_subscriberCount = 0
data.btc_commentsPerHour = 0
data.btc_postsPerHour = 0