Skip to content

Commit d98bece

Browse files
authored
Refactor error handling in update_legacy_preferences.py (#11339)
1 parent 9b1af4c commit d98bece

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

scripts/migrations/update_legacy_preferences.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def update_preferences(keys: list[str]) -> list[str]:
5858
username = key.split('/')[2]
5959
with RunAs(username):
6060
web.ctx.site.save(new_prefs, 'Updating preferences')
61-
except infogami.infobase.client.ClientException:
61+
except (infogami.infobase.client.ClientException, KeyError, IndexError):
6262
retry_list.append(key)
6363

6464
return retry_list
@@ -78,21 +78,24 @@ def main(args):
7878

7979
print("Updating preferences in batches of 1,000...")
8080
batch_count = 1
81+
error_cases = []
8182
while affected_keys and not was_shutdown_requested():
8283
print(f" Beginning batch #{batch_count}...")
8384
cur_batch = affected_keys[:1000]
8485
affected_keys = affected_keys[1000:]
8586
keys_to_retry = update_preferences(cur_batch)
86-
affected_keys.extend(keys_to_retry)
87+
error_cases.extend(keys_to_retry)
8788
batch_count += 1
8889
print(f"{len(keys_to_retry)} keys have been added to the retry queue.")
8990

91+
print("\nAll keys processed")
92+
print(f"{len(error_cases)} key(s) could not be updated.")
93+
for key in error_cases:
94+
print(key)
9095
if was_shutdown_requested():
9196
print("Script terminated early due to shutdown request")
9297
return
9398

94-
print("All affected preferences have been updated.")
95-
9699

97100
def _parse_args():
98101
p = argparse.ArgumentParser(description=__doc__)

0 commit comments

Comments
 (0)