Skip to content

Commit 80fd41c

Browse files
fix ! safely detect Program checker changes (#279)
Handle household/individual checker and beneficiary_validator changes without crashing when values are None.
1 parent 297d50c commit 80fd41c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/country_workspace/signals.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ def invalidate_entities_on_datachecker_change(
6565
if not instance.pk:
6666
return
6767

68-
old_instance = Program.objects.filter(pk=instance.pk).first()
69-
70-
if (
71-
old_instance.household_checker.pk != instance.household_checker.pk
72-
or old_instance.individual_checker.pk != instance.individual_checker.pk
73-
or old_instance.beneficiary_validator.__class__ is not instance.beneficiary_validator.__class__
68+
if not (old_instance := Program.objects.filter(pk=instance.pk).first()):
69+
return
70+
pk = lambda o: getattr(o, "pk", None)
71+
bv_type = lambda i: type(i.beneficiary_validator) if getattr(i, "beneficiary_validator", None) else None
72+
if (pk(old_instance.household_checker), pk(old_instance.individual_checker), bv_type(old_instance)) != (
73+
pk(instance.household_checker),
74+
pk(instance.individual_checker),
75+
bv_type(instance),
7476
):
7577
_process_program(program=instance)

0 commit comments

Comments
 (0)