Serliazed import of an application and perhaps a table can result in formula fields with incorrect db column types
Describe the problem
Steps to reproduce
- Get the old personal finance template from prior to this MR https://gitlab.com/bramw/baserow/-/merge_requests/990
- Sync templates
- Install that template
- Observe that in its summaries table no aggregations work. Under the hood the formula fields are of "text" db column type in postgres, which doesn't match their FormulaField metadata.
Actual result
Baserow when importing fields into a table:
- Loops over all fields from the JSON
- Creates them one by one, calling .save
- The .save recalculates the formulas metadata. So they might be invalid after this if they have a dependency that hasn't been imported yet.
- Loops over all of the fields again calling "after_import_serialized"
- We recreate their dependency graph per formula
- We call .save again on each formula, this time the dependency will exist and it should be recalculated to have the correct metadata.
- But we never call
recreate_formula_field_if_needed
. Which means if this second .save call changed the db column type of the formula (error is text, to anything not text) then the db column will remain with the incorrect db column type.
Proposed fix
Just call recreate_formula_field_if_needed
in the loop mentioned above in step 3.
Edited by Nigel Gott