Skip to content

Fix divide function sometimes resulting in errors and fix up and make available round and int functions

Describe the problem

This MR fixes two bugs. I combined both into the same MR as they both rely on fixing the same unit test which was accidentally disabled in a previous release.

  1. Divide functions combined with If statements can cause errors due to a missing output_field, see the following formula for an example:
divide(1, if(true,1,1))
  1. The round and int functions introduced in 1.10.2 weren't actually added to the frontend and so were usable but not shown in the modal. They also had issues when dealing with invalid user input such as 1/0 and decimal numbers. I've fixed various small issues regarding these functions and the left/right functions which also need to only ever be given integers as values but also weren't properly handling 1/0 etc. See the changes backend/tests/baserow/contrib/database/formula/test_baserow_formula_results.py for a clearer summary of the buggy formulas which were fixed in this MR.
  2. I renamed the int function to trunc and changed it to always return the numeric postgres type like it should have been originally. All of our numbers in formula land always store numerics and so having a function that instead returned the completely seperate integer type was a bad idea. Thankfully this function was never shown in the GUI, but i've still left in the int function as an alias for the trunc function. The reason why int was introduced in the first place was various other formula functions like left, right and round want the integer postgres type as their second type and will not accept numeric. In this MR instead of using the BaserowInt function to ensure we can convert a numeric to and integer and pass it to these functions I instead just do this conversion entirely in the Django Expression land and only for these very specific parameters. This way we never need to worry about the integer type suddenly appearing in formulas.

Merge Request Checklist

Closes #1086 (closed) Closes #1095 (closed)

Edited by Nigel Gott

Merge request reports