Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions ado/schema/property_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,10 @@ def check_value_type(
valueType = context.data.get("valueType")
if valueType:
if valueType == ValueTypeEnum.NUMERIC_VALUE_TYPE:
if isinstance(value, str):
import logging

logger = logging.getLogger()
logger.warning(
f"TEMP: Detected string value, {value}, assigned NUMERIC_TYPE assuming due to prior bug. Will upgrade"
)
elif isinstance(value, list):
import logging

logger = logging.getLogger()
logger.warning(
f"TEMP: Detected list value, {value}, assigned NUMERIC_TYPE assuming due to prior bug. Will upgrade"
if type(value) not in {float, int} and value is not None:
raise ValueError(
f"ValueType was numeric but value was of type {type(value)}"
)
else:
if type(value) not in {float, int} and value is not None:
raise ValueError("Validation failed for NUMERIC_VALUE_TYPE")
elif valueType == ValueTypeEnum.STRING_VALUE_TYPE:
if not isinstance(value, str):
raise ValueError(
Expand Down Expand Up @@ -155,17 +142,6 @@ def set_value_type(self) -> "PropertyValue":
self.valueType = ValueTypeEnum.BLOB_VALUE_TYPE
elif isinstance(self.value, list):
self.valueType = ValueTypeEnum.VECTOR_VALUE_TYPE
elif self.valueType == ValueTypeEnum.NUMERIC_VALUE_TYPE and isinstance(
self.value, str
):
# TEMPORARY
self.valueType = ValueTypeEnum.STRING_VALUE_TYPE
elif self.valueType == ValueTypeEnum.NUMERIC_VALUE_TYPE and isinstance(
self.value, list
):
# TEMPORARY
self.valueType = ValueTypeEnum.VECTOR_VALUE_TYPE

return self

def __str__(self) -> str:
Expand Down
28 changes: 7 additions & 21 deletions tests/schema/test_property_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,16 @@ def test_property_value_checks_value_type(
# Values with the same type are fine, values of different types should fail
test_type, test_value = test_value_example
if test_type is not example_type:
# Due to a bug, as a temp measure special behaviour has been enabled
# Because it is temporary, we xfail it.
# This indicates it should fail but currently is being allows
#
# Passing str value with NUMERIC_VALUE_TYPE will change it to STRING_VALUE_TYPE
if type(test_value) is str and example_type is ValueTypeEnum.NUMERIC_VALUE_TYPE:
ConstitutivePropertyValue(
value=test_value, property=prop.descriptor(), valueType=example_type
)
pytest.xfail(
"Automatically changing value type from NUMERIC_VALUE_TYPE to STRING_VALUE_TYPE to match string value."
" This is being allowed temporarily but should fail"
)
elif (
if (
type(test_value) is str and example_type is ValueTypeEnum.NUMERIC_VALUE_TYPE
) or (
type(test_value) is list
and example_type is ValueTypeEnum.NUMERIC_VALUE_TYPE
):
ConstitutivePropertyValue(
value=test_value, property=prop.descriptor(), valueType=example_type
)
pytest.xfail(
"Automatically changing value type from NUMERIC_VALUE_TYPE to VECTOR_VALUE_TYPE to match list value."
" This is being allowed temporarily but should fail"
)
with pytest.raises(pydantic.ValidationError):
ConstitutivePropertyValue(
value=test_value, property=prop.descriptor(), valueType=example_type
)
elif type(test_value) is str and example_type is ValueTypeEnum.BLOB_VALUE_TYPE:
# strings with BLOB_VALUE_TYPE are ALLOWED to be converted to bytes
# i.e. this is not the same case as previous two
Expand Down