Updating formula field doesn't delete incompatible filters and sorts
- Create a datetime formula
- Apply a today filter
- Edit the formula be
1
- Save the formula
- Refresh the page, you can no longer access the view
The cause: We never delete any viewfilters or sorts that don't work with the new formula type after changing it.
See FieldHandler.update_field
:
baserow_field_type_changed = from_field_type.type != to_field_type_name
field_cache = FieldCache()
if baserow_field_type_changed:
to_field_type = field_type_registry.get(to_field_type_name)
if field.primary and not to_field_type.can_be_primary_field:
raise IncompatiblePrimaryFieldTypeError(to_field_type_name)
dependants_broken_due_to_type_change = (
from_field_type.get_dependants_which_will_break_when_field_type_changes(
field, to_field_type, field_cache
)
)
new_model_class = to_field_type.model_class
field.change_polymorphic_type_to(new_model_class)
# If the field type changes it could be that some dependencies,
# like filters or sortings need to be changed.
ViewHandler().field_type_changed(field)
ViewHandler().field_type_changed(field)
is the function that should be called when a field type changes to invalidate all of its filters etc.
However for formulas baserow_field_type_changed = from_field_type.type != to_field_type_name
is always false, even though its actual underlying database column has changed.
So we need some separate check, ideally in some sort for FormulaFieldType.xyz method that calls ViewHandler().field_type_changed(field)
if the formula.type
is changing as the result of an update_field
call
Edited by Nigel Gott