From 11091003a718f191e591c1bf5ee7aff64f78c7ad 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..b47f4ab04 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 "Request was throttled" in page.get("detail", ""): + raise e + else: + self.stdout.write(f"Error: {e}") url = page.get("next") Person.objects.filter(ynr_id__in=merged_ids).delete()