mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-11 07:51:20 +00:00
Merge branch '3101-keyerror-in-adhoc-filter' into 'develop'
#3101 handle missing value key in adhoc filters Closes #3101 See merge request baserow/baserow!2786
This commit is contained in:
commit
3438c1074f
3 changed files with 54 additions and 1 deletions
backend
src/baserow/contrib/database/api/views
tests/baserow/contrib/database/view
changelog/entries/unreleased/bug
|
@ -686,7 +686,8 @@ class PublicViewFilterSerializer(serializers.Serializer):
|
|||
|
||||
from baserow.contrib.database.views.filters import sanitize_adhoc_filter_value
|
||||
|
||||
data["value"] = sanitize_adhoc_filter_value(data["value"])
|
||||
if value := data.get("value"):
|
||||
data["value"] = sanitize_adhoc_filter_value(value)
|
||||
return super().to_internal_value(data)
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import json
|
|||
from django.http import HttpRequest
|
||||
|
||||
import pytest
|
||||
from rest_framework.exceptions import ErrorDetail
|
||||
|
||||
from baserow.contrib.database.api.views.exceptions import (
|
||||
FiltersParamValidationException,
|
||||
|
@ -67,6 +68,50 @@ def test_adhoc_filters_from_dict():
|
|||
assert adhoc_filters.api_filters["filters"][0]["value"] == "a"
|
||||
|
||||
|
||||
def test_adhoc_filters_without_value_field():
|
||||
"""
|
||||
Test filter payload without `value` field.
|
||||
|
||||
We do some transformations of `value` key in
|
||||
`PublicViewFilterSerializer.to_internal_value()`, which happens before per-field
|
||||
serialization. This is a regression test to ensure that a missing `value` will be
|
||||
noticed and will raise a proper validation exception.
|
||||
"""
|
||||
|
||||
data = {
|
||||
"groups": [],
|
||||
"filter_type": "OR",
|
||||
"filters": [
|
||||
{
|
||||
"field": 123,
|
||||
"type": "contains",
|
||||
},
|
||||
],
|
||||
}
|
||||
with pytest.raises(FiltersParamValidationException) as err:
|
||||
AdHocFilters.from_dict(data)
|
||||
expected_err = {
|
||||
"error": ErrorDetail(
|
||||
string="ERROR_FILTERS_PARAM_VALIDATION_ERROR", code="error"
|
||||
),
|
||||
"detail": {
|
||||
"filters": {
|
||||
0: {
|
||||
"value": [
|
||||
{
|
||||
"error": ErrorDetail(
|
||||
string="This field is required.", code="required"
|
||||
),
|
||||
"code": ErrorDetail(string="required", code="error"),
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
assert err.value.detail == expected_err
|
||||
|
||||
|
||||
def test_deserialize_dispatch_filters():
|
||||
filters = {
|
||||
"groups": [],
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "bug",
|
||||
"message": "handle missing value key in adhoc filters",
|
||||
"issue_number": 3101,
|
||||
"bullet_points": [],
|
||||
"created_at": "2024-10-11"
|
||||
}
|
Loading…
Add table
Reference in a new issue