Skip to content

Commit 0ab58c8

Browse files
authored
Return proper error when creating autonumber field with form view (baserow#4646)
1 parent c8b83e6 commit 0ab58c8

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

backend/src/baserow/contrib/database/api/fields/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,8 @@
214214
HTTP_400_BAD_REQUEST,
215215
"Cannot set this constraint when default value is set.",
216216
)
217+
ERROR_VIEW_NOT_SUPPORTED = (
218+
"ERROR_VIEW_NOT_SUPPORTED",
219+
HTTP_400_BAD_REQUEST,
220+
"Cannot use the view type.",
221+
)

backend/src/baserow/contrib/database/api/fields/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
ERROR_RESERVED_BASEROW_FIELD_NAME,
6060
ERROR_SELECT_OPTION_DOES_NOT_BELONG_TO_FIELD,
6161
ERROR_TABLE_HAS_NO_PRIMARY_FIELD,
62+
ERROR_VIEW_NOT_SUPPORTED,
6263
)
6364
from baserow.contrib.database.api.rows.errors import ERROR_ROW_DOES_NOT_EXIST
6465
from baserow.contrib.database.api.tables.errors import (
@@ -118,6 +119,7 @@
118119
from baserow.contrib.database.table.handler import TableHandler
119120
from baserow.contrib.database.tokens.exceptions import NoPermissionToTable
120121
from baserow.contrib.database.tokens.handler import TokenHandler
122+
from baserow.contrib.database.views.exceptions import ViewDoesNotSupportListingRows
121123
from baserow.core.action.registries import action_type_registry
122124
from baserow.core.db import atomic_with_retry_on_deadlock, specific_iterator
123125
from baserow.core.exceptions import UserNotInWorkspace
@@ -295,6 +297,7 @@ def get(self, request, table_id):
295297
InvalidFieldConstraint: ERROR_INVALID_FIELD_CONSTRAINT,
296298
ImmutableFieldProperties: ERROR_IMMUTABLE_FIELD_PROPERTIES,
297299
FieldConstraintDoesNotSupportDefaultValueError: ERROR_FIELD_CONSTRAINT_DOES_NOT_SUPPORT_DEFAULT_VALUE,
300+
ViewDoesNotSupportListingRows: ERROR_VIEW_NOT_SUPPORTED,
298301
}
299302
)
300303
def post(self, request, data, table_id):

backend/tests/baserow/contrib/database/api/fields/test_field_views_types.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,3 +1840,25 @@ def test_lookup_field_type(api_client, data_fixture):
18401840
response_json = response.json()
18411841
assert response.status_code == HTTP_400_BAD_REQUEST
18421842
assert response_json["error"] == "ERROR_REQUEST_BODY_VALIDATION"
1843+
1844+
1845+
@pytest.mark.django_db
1846+
def test_autonumber_field_type_create_fails_form_view(api_client, data_fixture):
1847+
user, token = data_fixture.create_user_and_token()
1848+
table = data_fixture.create_database_table(user=user)
1849+
view = data_fixture.create_form_view(user=user, table=table)
1850+
1851+
response = api_client.post(
1852+
reverse("api:database:fields:list", kwargs={"table_id": table.id}),
1853+
{
1854+
"name": "autonumber_field",
1855+
"type": "autonumber",
1856+
"view_id": view.id,
1857+
},
1858+
format="json",
1859+
HTTP_AUTHORIZATION=f"JWT {token}",
1860+
)
1861+
1862+
response_json = response.json()
1863+
assert response.status_code == HTTP_400_BAD_REQUEST, response_json
1864+
assert response_json["error"] == "ERROR_VIEW_NOT_SUPPORTED"

0 commit comments

Comments
 (0)