Local Baserow upsert row service dispatch raises a validation error on read-only field types.
In !1871 (merged) the upsert row service's dispatch_data
method started performing two validation checks: it'll execute run_validation
based on the field type's serializer field, then call prepare_value_for_db
on the field type, so that any validation/transformation that needs to happen at the API level (former) and registry (latter) are run.
This works, but not on field types flagged as read_only=True
. In those, prepare_value_for_db
will raise a ValidationError
:
Field of type {self.type} is read only and should not be set manually.
The following may suffice as a fix, but needs further testing to be sure.
index c71eb5426..d42a5bc17 100644
--- a/backend/src/baserow/contrib/integrations/local_baserow/service_types.py
+++ b/backend/src/baserow/contrib/integrations/local_baserow/service_types.py
@@ -1230,16 +1230,20 @@ class LocalBaserowUpsertRowServiceType(LocalBaserowTableServiceType):
serializer_field = field_type.get_serializer_field(field.specific)
resolved_value = serializer_field.run_validation(resolved_value)
- # Then transform and validate the resolved value for prepare value for db.
- try:
- field_values[field.db_column] = field_type.prepare_value_for_db(
- field.specific, resolved_value
- )
- except ValidationError as exc:
- raise ServiceImproperlyConfigured(
- "The result value of the formula is not valid for the "
- f"field `{field.name} ({field.db_column})`: {exc.message}"
- ) from exc
+ # Then transform and validate the resolved value for prepare value for db,
+ # if the field type is not readonly.
+ if not field_type.read_only:
+ try:
+ field_values[field.db_column] = field_type.prepare_value_for_db(
+ field.specific, resolved_value
+ )
+ except ValidationError as exc:
+ raise ServiceImproperlyConfigured(
+ "The result value of the formula is not valid for the "
+ f"field `{field.name} ({field.db_column})`: {exc.message}"
+ ) from exc
+ else:
+ field_values[field.db_column] = resolved_value
if resolved_values["row_id"]:
row = RowHandler().update_row_by_id(