From b1c57daaddb2b316c957819ebc554d6efe680208 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 23 Jan 2026 16:31:42 +0000 Subject: [PATCH] Improve the Local Baserow single row service's error handling. (#4530) * Improve the GetRow service's error handling, instead of raising DoesNotExist, use ServiceImproperlyConfiguredDispatchException like other services. * Lint fix --- .../local_baserow/service_types.py | 8 ++++++-- .../baserow/locale/en/LC_MESSAGES/django.po | 18 +++++++++++++----- .../service_types/test_get_row_service_type.py | 7 +++---- ...g_in_the_local_baserow_single_table_ro.json | 9 +++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 changelog/entries/unreleased/bug/improved_error_handling_in_the_local_baserow_single_table_ro.json diff --git a/backend/src/baserow/contrib/integrations/local_baserow/service_types.py b/backend/src/baserow/contrib/integrations/local_baserow/service_types.py index ee6b1bb43c..df3db9615b 100644 --- a/backend/src/baserow/contrib/integrations/local_baserow/service_types.py +++ b/backend/src/baserow/contrib/integrations/local_baserow/service_types.py @@ -18,6 +18,7 @@ from django.db import transaction from django.db.models import QuerySet from django.dispatch import Signal +from django.utils.translation import gettext as _ from rest_framework import serializers from rest_framework.exceptions import ValidationError as DRFValidationError @@ -1656,6 +1657,7 @@ def dispatch_data( :param resolved_values: If the service has any formulas, this dictionary will contain their resolved values. :param dispatch_context: The context used for the dispatch. + :raises ServiceImproperlyConfiguredDispatchException: When no rows are found. :return: The rows. """ @@ -1671,7 +1673,7 @@ def dispatch_data( # row by setting the right condition if "row_id" not in resolved_values: if not queryset.exists(): - raise DoesNotExist() + raise ServiceImproperlyConfiguredDispatchException(_("No rows found")) return { "data": queryset.first(), "baserow_table_model": table_model, @@ -1686,7 +1688,9 @@ def dispatch_data( "public_allowed_properties": only_field_names, } except table_model.DoesNotExist: - raise DoesNotExist() + raise ServiceImproperlyConfiguredDispatchException( + _(f"Row {resolved_values['row_id']} does not exist.") + ) def dispatch_transform(self, dispatch_data: Dict[str, Any]) -> DispatchResult: """ diff --git a/backend/src/baserow/locale/en/LC_MESSAGES/django.po b/backend/src/baserow/locale/en/LC_MESSAGES/django.po index 67b9120a1e..e16f37e48a 100755 --- a/backend/src/baserow/locale/en/LC_MESSAGES/django.po +++ b/backend/src/baserow/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-11-17 15:17+0000\n" +"POT-Creation-Date: 2026-01-09 16:13+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -35,15 +35,15 @@ msgstr "" #: src/baserow/contrib/automation/action_scopes.py:14 #, python-format msgid "" -"of type (%(node_type)s) in automation \"%(automation_name)s\" " -"(%(automation_id)s)." +"of type (%(node_type)s) in automation " +"\"%(automation_name)s\" (%(automation_id)s)." msgstr "" #: src/baserow/contrib/automation/actions.py:8 #, python-format msgid "" -"in workflow (%(workflow_id)s) in automation \"%(automation_name)s\" " -"(%(automation_id)s)." +"in workflow (%(workflow_id)s) in automation " +"\"%(automation_name)s\" (%(automation_id)s)." msgstr "" #: src/baserow/contrib/automation/automation_init_application.py:29 @@ -221,6 +221,14 @@ msgstr "" msgid "Triggered at" msgstr "" +#: src/baserow/contrib/integrations/local_baserow/service_types.py:1676 +msgid "No rows found" +msgstr "" + +#: src/baserow/contrib/integrations/local_baserow/service_types.py:1692 +msgid "Row {resolved_values['row_id']} does not exist." +msgstr "" + #: src/baserow/contrib/integrations/slack/service_types.py:166 msgid "OK" msgstr "" diff --git a/backend/tests/baserow/contrib/integrations/local_baserow/service_types/test_get_row_service_type.py b/backend/tests/baserow/contrib/integrations/local_baserow/service_types/test_get_row_service_type.py index 81bcb1b107..e3e9745734 100644 --- a/backend/tests/baserow/contrib/integrations/local_baserow/service_types/test_get_row_service_type.py +++ b/backend/tests/baserow/contrib/integrations/local_baserow/service_types/test_get_row_service_type.py @@ -16,7 +16,6 @@ ) from baserow.core.exceptions import PermissionException from baserow.core.services.exceptions import ( - DoesNotExist, InvalidContextContentDispatchException, ServiceImproperlyConfiguredDispatchException, ) @@ -257,7 +256,7 @@ def test_local_baserow_get_row_service_dispatch_data_with_view_filter(data_fixtu dispatch_context = FakeDispatchContext() dispatch_values = service_type.resolve_service_formulas(service, dispatch_context) - with pytest.raises(DoesNotExist): + with pytest.raises(ServiceImproperlyConfiguredDispatchException): service_type.dispatch_data(service, dispatch_values, dispatch_context) @@ -291,7 +290,7 @@ def test_local_baserow_get_row_service_dispatch_data_with_service_search( dispatch_context = FakeDispatchContext() dispatch_values = service_type.resolve_service_formulas(service, dispatch_context) - with pytest.raises(DoesNotExist): + with pytest.raises(ServiceImproperlyConfiguredDispatchException): service_type.dispatch_data(service, dispatch_values, dispatch_context) @@ -422,7 +421,7 @@ def test_local_baserow_get_row_service_dispatch_data_row_not_exist(data_fixture) dispatch_context = FakeDispatchContext() dispatch_values = service_type.resolve_service_formulas(service, dispatch_context) - with pytest.raises(DoesNotExist): + with pytest.raises(ServiceImproperlyConfiguredDispatchException): service_type.dispatch_data(service, dispatch_values, dispatch_context) diff --git a/changelog/entries/unreleased/bug/improved_error_handling_in_the_local_baserow_single_table_ro.json b/changelog/entries/unreleased/bug/improved_error_handling_in_the_local_baserow_single_table_ro.json new file mode 100644 index 0000000000..58414cd338 --- /dev/null +++ b/changelog/entries/unreleased/bug/improved_error_handling_in_the_local_baserow_single_table_ro.json @@ -0,0 +1,9 @@ +{ + "type": "bug", + "message": "Improved error handling in the Local Baserow single table row action.", + "issue_origin": "github", + "issue_number": null, + "domain": "integration", + "bullet_points": [], + "created_at": "2026-01-09" +} \ No newline at end of file