1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-03-10 02:52:25 +00:00

handle null payload for file field

This commit is contained in:
Cezary Statkiewicz 2024-12-18 18:57:35 +01:00
parent 188a284f9c
commit 60e514e43c
3 changed files with 27 additions and 0 deletions
backend
src/baserow/contrib/database/fields
tests/baserow/contrib/database/field
changelog/entries/unreleased/bug

View file

@ -3487,6 +3487,8 @@ class FileFieldType(FieldType):
# to validate if the file actually exists and to get the 'real' properties
# from it.
provided_files = []
if not value:
return provided_files
for o in value:
provided_files.append(o)
return provided_files
@ -3541,6 +3543,11 @@ class FileFieldType(FieldType):
name_map[name].append(row_index)
if not name_map:
# ensure we're not returning None for any row
for k, v in values_by_row.items():
if v is None:
values_by_row[k] = []
return values_by_row
unique_names = set(name_map.keys())

View file

@ -124,6 +124,19 @@ def test_file_field_type(data_fixture):
assert row.file[1] == user_file_3.serialize()
assert row.file[2] == user_file_2.serialize()
# test for https://gitlab.com/baserow/baserow/-/issues/2906
updated_rows = row_handler.update_rows(
user=user,
table=table,
rows_values=[{"id": row.id, file.db_column: None}],
send_realtime_update=False,
send_webhook_events=False,
skip_search_update=True,
)
assert updated_rows.updated_rows[0].id == row.id
assert getattr(updated_rows.updated_rows[0], file.db_column) == []
row = row_handler.update_row_by_id(
user=user,
table=table,

View file

@ -0,0 +1,7 @@
{
"type": "bug",
"message": "handle null payload for file field",
"issue_number": 2906,
"bullet_points": [],
"created_at": "2024-12-18"
}