1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-17 10:22:36 +00:00

Merge branch 'local-baserow-service-action-type-fix' into 'develop'

Local Baserow upsert service prepare_value_for_db tweak

See merge request 
This commit is contained in:
Peter Evans 2024-10-17 08:07:36 +00:00
commit 4852b2dab6
4 changed files with 18 additions and 45 deletions
backend/src/baserow/contrib
database/rows
integrations/local_baserow
changelog/entries/unreleased/bug

View file

@ -148,7 +148,6 @@ class CreateRowsActionType(UndoableActionType):
rows_values: List[Dict[str, Any]],
before_row: Optional[GeneratedTableModel] = None,
model: Optional[Type[GeneratedTableModel]] = None,
values_already_prepared: bool = False,
) -> List[GeneratedTableModel]:
"""
Creates rows for a given table with the provided values if the user
@ -164,9 +163,6 @@ class CreateRowsActionType(UndoableActionType):
the row with this id.
:param model: If the correct model has already been generated it can be
provided so that it does not have to be generated for a second time.
:param values_already_prepared: Whether or not the values are already sanitized
and validated for every field and can be used directly by the handler
without any further check.
:return: The created list of rows instances.
"""
@ -181,7 +177,6 @@ class CreateRowsActionType(UndoableActionType):
rows_values,
before_row=before_row,
model=model,
values_already_prepared=values_already_prepared,
)
workspace = table.database.workspace
@ -767,7 +762,6 @@ class UpdateRowsActionType(UndoableActionType):
table: Table,
rows_values: List[Dict[str, Any]],
model: Optional[Type[GeneratedTableModel]] = None,
values_already_prepared: bool = False,
) -> List[GeneratedTableModelForUpdate]:
"""
Updates field values in batch based on provided rows with the new values.
@ -782,9 +776,6 @@ class UpdateRowsActionType(UndoableActionType):
field ids plus the id of the row.
:param model: If the correct model has already been generated it can be
provided so that it does not have to be generated for a second time.
:param values_already_prepared: Whether or not the values are already sanitized
and validated for every field and can be used directly by the handler
without any further check.
:return: The updated rows.
"""
@ -795,7 +786,6 @@ class UpdateRowsActionType(UndoableActionType):
table,
rows_values,
model=model,
values_already_prepared=values_already_prepared,
)
updated_rows = result.updated_rows

View file

@ -1076,7 +1076,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
send_webhook_events: bool = True,
generate_error_report: bool = False,
skip_search_update: bool = False,
values_already_prepared: bool = False,
) -> List[GeneratedTableModel]:
"""
Creates new rows for a given table without checking permissions. It also calls
@ -1097,9 +1096,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
:param skip_search_update: If you want to instead trigger the search handler
cells update later on after many create_rows calls then set this to True
but make sure you trigger it eventually.
:param values_already_prepared: Whether or not the values are already sanitized
and validated for every field and can be used directly by the handler
without any further check.
:return: The created row instances.
"""
@ -1114,15 +1110,12 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
)
report = {}
if values_already_prepared:
prepared_rows_values = [deepcopy(row_values) for row_values in rows_values]
else:
prepared_rows_values, errors = self.prepare_rows_in_bulk(
model._field_objects,
rows_values,
generate_error_report=generate_error_report,
)
report.update({index: err for index, err in errors.items()})
prepared_rows_values, errors = self.prepare_rows_in_bulk(
model._field_objects,
rows_values,
generate_error_report=generate_error_report,
)
report.update({index: err for index, err in errors.items()})
rows_relationships = []
for index, row in enumerate(
@ -1231,7 +1224,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
send_webhook_events: bool = True,
generate_error_report: bool = False,
skip_search_update: bool = False,
values_already_prepared: bool = False,
) -> List[GeneratedTableModel]:
"""
Creates new rows for a given table if the user
@ -1277,7 +1269,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
send_webhook_events,
generate_error_report,
skip_search_update,
values_already_prepared,
)
def update_dependencies_of_rows_created(
@ -1678,7 +1669,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
send_realtime_update: bool = True,
send_webhook_events: bool = True,
skip_search_update: bool = False,
values_already_prepared: bool = False,
) -> UpdatedRowsWithOldValuesAndMetadata:
"""
Updates field values in batch based on provided rows with the new
@ -1699,9 +1689,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
:param skip_search_update: If you want to instead trigger the search handler
cells update later on after many create_rows calls then set this to True
but make sure you trigger it eventually.
:param values_already_prepared: Whether or not the values are already sanitized
and validated for every field and can be used directly by the handler
without any further check.
:raises RowIdsNotUnique: When trying to update the same row multiple
times.
:raises RowDoesNotExist: When any of the rows don't exist.
@ -1714,12 +1701,9 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
user_id = user and user.id
if values_already_prepared:
prepared_rows_values = [deepcopy(row_values) for row_values in rows_values]
else:
prepared_rows_values, _ = self.prepare_rows_in_bulk(
model._field_objects, rows_values
)
prepared_rows_values, _ = self.prepare_rows_in_bulk(
model._field_objects, rows_values
)
row_ids = [r["id"] for r in prepared_rows_values]
non_unique_ids = get_non_unique_values(row_ids)
@ -1939,7 +1923,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
send_realtime_update: bool = True,
send_webhook_events: bool = True,
skip_search_update: bool = False,
values_already_prepared: bool = False,
) -> UpdatedRowsWithOldValuesAndMetadata:
"""
Updates field values in batch based on provided rows with the new
@ -1960,9 +1943,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
:param skip_search_update: If you want to instead trigger the search handler
cells update later on after many create_rows calls then set this to True
but make sure you trigger it eventually.
:param values_already_prepared: Whether or not the values are already sanitized
and validated for every field and can be used directly by the handler
without any further check.
:raises RowIdsNotUnique: When trying to update the same row multiple
times.
:raises RowDoesNotExist: When any of the rows don't exist.
@ -1986,7 +1966,6 @@ class RowHandler(metaclass=baserow_trace_methods(tracer)):
send_realtime_update,
send_webhook_events,
skip_search_update,
values_already_prepared,
)
def get_rows(

View file

@ -1614,9 +1614,8 @@ class LocalBaserowUpsertRowServiceType(
# Then transform and validate the resolved value for prepare value for db.
try:
row_values[field.db_column] = field_type.prepare_value_for_db(
field.specific, resolved_value
)
field_type.prepare_value_for_db(field.specific, resolved_value)
row_values[field.db_column] = resolved_value
except ValidationError as exc:
raise ServiceImproperlyConfigured(
"The result value of the formula is not valid for the "
@ -1632,7 +1631,6 @@ class LocalBaserowUpsertRowServiceType(
table,
rows_values=[{**row_values, "id": row_id}],
model=model,
values_already_prepared=True,
)
except RowDoesNotExist as exc:
raise ServiceImproperlyConfigured(
@ -1645,7 +1643,6 @@ class LocalBaserowUpsertRowServiceType(
table=table,
rows_values=[row_values],
model=model,
values_already_prepared=True,
)
except CannotCreateRowsInTable as exc:
raise ServiceImproperlyConfigured(

View file

@ -0,0 +1,7 @@
{
"type": "bug",
"message": "[Builder] Resolved an issue with creating and updating rows in workflow actions.",
"issue_number": null,
"bullet_points": [],
"created_at": "2024-10-16"
}