aas-core-works / aas-core3.0-python

Manipulate, verify and de/serialize asset administration shells in Python.
Other
4 stars 0 forks source link

No path for validation of value #22

Closed mhrimaz closed 4 months ago

mhrimaz commented 4 months ago

Inconsistent value error does not provide a path. The error for idShort has a path, but the error for the value format does not have a path.

print("\n#Before!\n")
# Let's build a simple property.
some_element = aas_types.Property(
    id_short="Built Date",
    value_type=aas_types.DataTypeDefXSD.DATE,
    value="24.09.2024"
)
# Then we serialize it into the JSON.
jsonable = aas_jsonization.to_jsonable(some_element)

# Print the mapping as json
print(json.dumps(jsonable, indent=2))

# The model was invalid!
print("Validation report:")
for error in aas_verification.verify(some_element):
    print(f"{error.path}: {error.cause}")

output:

{
  "idShort": "Built Date",
  "valueType": "xs:date",
  "value": "24.09.2024",
  "modelType": "Property"
}
Validation report:
: Value must be consistent with the value type.
.id_short: ID-short of Referables shall only feature letters, digits, underscore (``_``); starting mandatory with a letter. *I.e.* ``[a-zA-Z][a-zA-Z0-9_]*``.

My expectation is the following, but maybe I am wrong. I just wanted to clarify whether this is intentional or not.

.value : Value must be consistent with the value type.
mristin commented 4 months ago

Hi @mhrimaz !

This is intentional. The error can be with either .value or `.value_type. Therefore, the constraint is defined at the level of Property, and not at the level of Property.value.

If my explanation is confusing: think of the context of the constraints. All the "ingredients" for a constraint need to be in the context.

mristin commented 4 months ago

(I closed the issue as it is not something we can fix, but feel free to continue the discussion.)