Fix formula with now and field functions not always periodically refreshing
The Bug
- Make any date field
- Make a formula with a
now()
and a reference to another field likenow() > field('date field')
- See that this formula is never refreshed periodically
The problem
def get_fields_needing_periodic_update(self) -> Optional[QuerySet]:
return (
FormulaField.objects.filter(needs_periodic_update=True)
.annotate(num_dependencies=Count("field_dependencies"))
.filter(num_dependencies=0)
)
This is incorrect and is only selecting formulas which have no dependencies. This means because the formula above has a dependency on field('date field')
it will no longer get updates.
Instead it should be
def get_fields_needing_periodic_update(self) -> Optional[QuerySet]:
return (
FormulaField.objects.filter(needs_periodic_update=True)
.annotate(num_dependants=Count("field_dependants"))
.filter(num_dependants=0)
)
Edited by Nigel Gott