From 796f569fbab8f23880469ff86f93bf5616a1b194 Mon Sep 17 00:00:00 2001 From: JunsongDu Date: Tue, 23 Jul 2024 10:57:03 +0200 Subject: [PATCH 1/3] fix: allow empty string as value for any data type --- filip/models/ngsi_v2/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filip/models/ngsi_v2/base.py b/filip/models/ngsi_v2/base.py index d0909d4a..e07728c5 100644 --- a/filip/models/ngsi_v2/base.py +++ b/filip/models/ngsi_v2/base.py @@ -410,7 +410,7 @@ def validate_value_type(cls, value, info: ValidationInfo): value_ = value.model_dump() validate_escape_character_free(value_) - if value is not None: + if value is not None and value is not "": if type_ == DataType.TEXT: if isinstance(value, list): return [str(item) for item in value] @@ -445,6 +445,7 @@ def validate_value_type(cls, value, info: ValidationInfo): raise TypeError( f"{type(value)} does not match " f"{DataType.OBJECT}" ) + # allows geojson as structured value if type_ == DataType.GEOJSON: if isinstance( @@ -461,7 +462,6 @@ def validate_value_type(cls, value, info: ValidationInfo): ), ): return value - if isinstance(value, dict): _geo_json_type = value.get("type", None) if _geo_json_type == "Point": From ee7c41b0b7e56a05c6f07b6ab33f844a9019234d Mon Sep 17 00:00:00 2001 From: JunsongDu Date: Tue, 23 Jul 2024 11:06:04 +0200 Subject: [PATCH 2/3] chore: include " " in ignore list --- filip/models/ngsi_v2/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filip/models/ngsi_v2/base.py b/filip/models/ngsi_v2/base.py index e07728c5..a902bb14 100644 --- a/filip/models/ngsi_v2/base.py +++ b/filip/models/ngsi_v2/base.py @@ -410,7 +410,7 @@ def validate_value_type(cls, value, info: ValidationInfo): value_ = value.model_dump() validate_escape_character_free(value_) - if value is not None and value is not "": + if value not in (None, "", " "): if type_ == DataType.TEXT: if isinstance(value, list): return [str(item) for item in value] From 4f35e1a51c89ffaa3e1154c8b72fd788baa685d6 Mon Sep 17 00:00:00 2001 From: JunsongDu Date: Tue, 23 Jul 2024 11:08:13 +0200 Subject: [PATCH 3/3] doc: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b60ddb52..905603b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - add: flag to determine the deletion of registration when clearing the CB ([#267](https://github.com/RWTH-EBC/FiLiP/pull/267)) - fix: rework tutorials for pydantic v2 ([#259](https://github.com/RWTH-EBC/FiLiP/pull/259)) - fix: inconsistency of `entity_type` as required argument ([#188](https://github.com/RWTH-EBC/FiLiP/pull/188)) +- fix: allow empty string in attribute value validation ([#311](https://github.com/RWTH-EBC/FiLiP/pull/311)) ### v0.4.1 - fix: Session added as optional parameter to enable tls communication with clients ([#249](https://github.com/RWTH-EBC/FiLiP/pull/249))