Skip to content

Commit

Permalink
Fix bug with attachments being pruned due to case/whitespace sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
quis committed Feb 25, 2025
1 parent c92e714 commit 47b6ad6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/models/template_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
import json

from notifications_utils.insensitive_dict import InsensitiveDict
from notifications_utils.insensitive_dict import InsensitiveSet as UtilsInsensitiveSet

from app.extensions import redis_client
from app.models import JSONModel

# Implements https://github.com/alphagov/notifications-utils/pull/1197/files
class InsensitiveSet(UtilsInsensitiveSet):
def __contains__(self, key):
return key in InsensitiveDict.from_keys(self)


class TemplateAttachment(JSONModel):
file_name: str
Expand Down Expand Up @@ -63,7 +69,7 @@ def __delitem__(self, placeholder_name):
@property
def count(self):
return sum(
bool(self[key]) for key in self._dict if key in InsensitiveDict.from_keys(self._template.all_placeholders)
bool(self[key]) for key in self._dict if key in InsensitiveSet(self._template.all_placeholders)
)

@property
Expand All @@ -77,5 +83,5 @@ def as_personalisation(self):

def prune_orphans(self):
for placeholder in self._dict.keys():
if placeholder not in self._template.all_placeholders:
if placeholder not in InsensitiveSet(self._template.all_placeholders):
del self[placeholder]

0 comments on commit 47b6ad6

Please sign in to comment.