Skip to content

Commit

Permalink
[staged-updates] Production failure of an exclusion criteria in a que…
Browse files Browse the repository at this point in the history
…ry filter. Of course it did.
  • Loading branch information
biblicabeebli committed Jan 21, 2025
1 parent 1bda1ea commit 6bb5363
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
1 change: 0 additions & 1 deletion database/profiling_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions libs/shell_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions services/resend_push_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.")

Expand Down

0 comments on commit 6bb5363

Please sign in to comment.