From 6bb536334825628bd2fa2bbf7c0d7a445806e3c3 Mon Sep 17 00:00:00 2001 From: Eli Jones Date: Tue, 21 Jan 2025 11:59:43 -0500 Subject: [PATCH] [staged-updates] Production failure of an exclusion criteria in a query filter. Of course it did. --- database/profiling_models.py | 1 - libs/shell_support.py | 44 +++++++++++++-------------- services/resend_push_notifications.py | 10 ++++-- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/database/profiling_models.py b/database/profiling_models.py index de53913c..a928c3d9 100644 --- a/database/profiling_models.py +++ b/database/profiling_models.py @@ -56,7 +56,6 @@ class LineEncryptionError(TimestampedModel): participant: Participant = models.ForeignKey(Participant, null=True, on_delete=models.PROTECT) - # WARNING: this table is huge. Several-to-many multiples of ChunkRegistry, though it is not as # complex and rows are individually less bulky. Never pull this table into memory, always use # .iterator() in combination with .values() or .values_list() and test your query on your largest diff --git a/libs/shell_support.py b/libs/shell_support.py index 136c1168..4ecb98ae 100644 --- a/libs/shell_support.py +++ b/libs/shell_support.py @@ -84,16 +84,16 @@ def SURVEY(id_or_name: Union[str, int]): """ Get a Survey, can be a website-style key, a primary key, or a name on a contains match. """ if isinstance(id_or_name, int): ret = Survey.objects.get(pk=id_or_name) - - try: - ret = Survey.objects.get(object_id=id_or_name) - except Survey.DoesNotExist: - surveys = Survey.fltr(name__icontains=id_or_name) - if surveys.count() == 0: - raise Survey.DoesNotExist() from None - if surveys.count() == 1: - return surveys.get() - pprint(list(surveys.values_list("name", "id"))) + else: + try: + ret = Survey.objects.get(object_id=id_or_name) + except Survey.DoesNotExist: + surveys = Survey.fltr(name__icontains=id_or_name) + if surveys.count() == 0: + raise Survey.DoesNotExist() from None + if surveys.count() == 1: + return surveys.get() + pprint(list(surveys.values_list("name", "id"))) if ret.name: print(ret.name) @@ -106,18 +106,18 @@ def STUDY(id_or_name: Union[str, int]): """ Get a Study, can be a website-style key, a primary key, or a name on a contains match. """ if isinstance(id_or_name, int): ret = Study.objects.get(pk=id_or_name) - - try: - ret = Study.objects.get(object_id=id_or_name) - except Study.DoesNotExist: - studies = Study.fltr(name__icontains=id_or_name) - count = studies.count() - if count == 1: - return studies.get() - if count < 1: - raise Study.DoesNotExist() from None - pprint(list(studies.values_list("name", "id"))) - return None + else: + try: + ret = Study.objects.get(object_id=id_or_name) + except Study.DoesNotExist: + studies = Study.fltr(name__icontains=id_or_name) + count = studies.count() + if count == 1: + return studies.get() + if count < 1: + raise Study.DoesNotExist() from None + pprint(list(studies.values_list("name", "id"))) + return None print(ret.name) return ret diff --git a/services/resend_push_notifications.py b/services/resend_push_notifications.py index e5c973ea..bccd7b87 100644 --- a/services/resend_push_notifications.py +++ b/services/resend_push_notifications.py @@ -223,7 +223,7 @@ def get_resendable_uuids(now: datetime, pushable_participant_pks: List[Participa TOO_EARLY = GlobalSettings.singleton().push_notification_resend_enabled # retired just means this flag has been set to True for some reason - retired_uuids = ScheduledEvent.objects.filter(no_resend=True).values_list("uuid", flat=True) + retired_uuids = set(ScheduledEvent.objects.filter(no_resend=True).values_list("uuid", flat=True)) # Now we can filter ArchivedEvents to get all that remain unconfirmed. uuid_info = list( @@ -234,14 +234,18 @@ def get_resendable_uuids(now: datetime, pushable_participant_pks: List[Participa participant_id__in=pushable_participant_pks, # from relevant participants, confirmed_received=False, # that are not confirmed received, uuid__isnull=False, # and have uuids. - ).exclude( - uuid__in=retired_uuids, # exclude schedules that have been retired. + # well this failed in preduction.... + # ).exclude( + # uuid__in=retired_uuids, # exclude schedules that have been retired. ).values_list( "uuid", "last_updated", "participant__study_id", ) ) + # probably due to too many uuids, excluding these from the query directly Simple Doesn't Work, + # so I guess to exclude it in python? + uuid_info = [info for info in uuid_info if info[0] not in retired_uuids] log(f"found {len(uuid_info)} ArchivedEvents to check.")