From 9f1419fbe163406ea9180f10a464126f0c91f5ec Mon Sep 17 00:00:00 2001 From: Virginia Dooley Date: Tue, 24 Oct 2023 13:55:20 +0100 Subject: [PATCH] Handle exception for rate limiting --- wcivf/apps/people/management/commands/import_people.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wcivf/apps/people/management/commands/import_people.py b/wcivf/apps/people/management/commands/import_people.py index 8b3481c25..b65c18771 100644 --- a/wcivf/apps/people/management/commands/import_people.py +++ b/wcivf/apps/people/management/commands/import_people.py @@ -253,8 +253,14 @@ def delete_merged_people(self): while url: req = requests.get(url) page = req.json() - for result in page["results"]: - merged_ids.append(result["old_person_id"]) + try: + for result in page["results"]: + merged_ids.append(result["old_person_id"]) + except KeyError as e: + if not "Request was throttled" in page.get("detail", ""): + self.stdout.write(f"Error: {e}") + else: + raise e url = page.get("next") Person.objects.filter(ynr_id__in=merged_ids).delete()