Changing Data Source Type can Break Formulas
What is in this MR
This MR fixes a bug with changing the Data Source type.
When changing the Data Source type from 'Get multiple rows' to 'Get single row', if an Element was using a formula from the data source, it could cause a crash when attempting to export or duplicate the app. Reloading the page could also result in an error.
Reproduce the Bug
To reproduce the bug behavior, make sure you're on the latest develop
branch, then follow the steps below.
- Create a Data Source using 'Get multiple rows' and point it to a table, e.g. the Customers table.
- Create a Table Element using this Data Source
- Create a Heading Element and set its Text to use a formula from the Data Source. E.g. in the Data Explorer, select Data records -> Data source -> 0 -> Name.
- [This is where the bug happens] Change the Data Source type to 'Get single row'. Select the same Customers table and pick an arbitrary Row ID, e.g. 2.
You should observe the following issues:
1. Formula Error
You will notice that the Heading element's context pane on the right-hand side now shows the formula with a light red background, indicating that the formula has an error.
2. Publish/Duplicate Error
Try to publish and/or duplicate the page. This will fail.
In the Celery Worker container, you should see an error like:
File "/baserow/backend/src/baserow/contrib/integrations/local_baserow/service_types.py", line 983, in import_path
original_field_id = int(field_dbname[6:])
~~~~~~~~~~~~^^^^
TypeError: 'int' object is not subscriptable
3. Error upon Reloading Page
Try to reload the page (use F5), and you should notice a general AB error saying:
Cannot read properties of undefined (reading 'length')
In the browser's dev console, you should see an error like this:
TypeError: Cannot read properties of undefined (reading 'length')
How to test this MR
Switch to this MR's branch and create a new App (because you won't be able to load the app/page you were testing earlier).
Then run the same testing steps as before. There should no errors or crashes.
Finally, change the Data Source back to 'Get multiple rows'. You should observe that the previously Table and Heading elements are now working again.
Test Bug Fix: Changing List rows to Get Row
This MR also fixes the following scenario:
In the latest develop
:
- In your database table, create a
file
field. Upload an image to it. - Back in your AB page, add a heading element.
- Add a
single row
data source (at the row where the file was uploaded) - Give it a value of
data_source
>file
>0
>url
. - Convert the data source to a
multiple row
data source. - Duplicate the application, we end up raising an exception.
After switching to this MR, the above steps should not cause any errors when duplicating/exporting the app.
Merge Request Checklist
-
A changelog entry has been created if required. -
New/updated Premium/Enterprise features are separated correctly in the premium or enterprise folder -
The latest Chrome and Firefox have been used to test any new frontend features -
Documentation has been updated -
Quality Standards are met -
Performance: tables are still fast with 100k+ rows, 100+ field tables -
The redoc API pages have been updated for any REST API changes -
Our custom API docs are updated for changes to endpoints accessed via api tokens -
The UI/UX has been updated following UI Style Guide
Closes #2730 (closed)