Export job running at same time field is deleted causes job to fail
What Happened?
If a view is exported and simultaneously a field from the view is hidden or deleted the export job will crash.
Expected result
The export job should properly handle trashed/deleted fields even when it happens concurrently.
Steps to reproduce
Hard to reproduce however if you look at baserow.contrib.database.views.view_types.GridViewType.get_visible_fields_and_model
and specifically the following order of operations:
- An export job is running and calls
GridViewType.get_visible_fields_and_model
- It gets to
ordered_visible_field_ids
and queries to get them. - If now another transaction deletes a field and commits,
ordered_visible_field_ids
now contains an id for a deleted field -
model = grid_view.table.get_model(field_ids=ordered_visible_field_ids)
is now run by theGridViewType.get_visible_fields_and_model
call - When
field_ids
are passed to aget_model
call it requeries the database for the fields with those id's, but only looks for non-trashed fields, it doesn't raise an exception if a field_id is given which it does not find but just builds a model with the fields it does. - As a result the returned model does not have the field which has been deleted.
- Finally
ordered_field_objects = [model._field_objects[field_id] for field_id in ordered_visible_field_ids]
crashes for thefield_id
which has been deleted.
We can do a number of things to fix this
- Instead of passing field ids into the
get_model
call we could instead just pass a list of field instances. This meansget_model
won't run a second query to get the fields and hence we can be sure the resulting model does have all the fields that we gave it. - We could gracefully handle the situation where the field_id is not in
_field_objects
(just skip it).
Screenshots
Priority/Severity
-
High (anything that impacts the normal user flow or blocks Baserow usage) -
Medium (anything that negatively affects the user experience) -
Low (anything else e.g., typos, missing icons, layout issues, etc.)
Edited by Nigel Gott