Comments (4)
Hmmm, possible solutions would be checking using issubclass
instead of is
when checking whether elements in the list are compatible with typeValueListElement
or using issubclass
when checking the class assigned to typeValueListElement
.
However, since custom class names wouldn't be compliant with the serialization, allowing other classes than those specified in KEY_TYPES_CLASSES
won't be possible. Thus, we'll probably go with the first solution.
from basyx-python-sdk.
@s-heppner Can you re-open this issue? It isn't resolved yet. We can discuss the possible solutions it in the next meeting.
from basyx-python-sdk.
I just had a look at the implementation again, and I think it's impossible to allow custom subclasses of SubmodelElements where a specific SubmodelElement
is expected. I used an explicit is
check, because isinstance
or issubclass
would also allow e.g. AnnotatedRelationshipElement
, where a RelationshipElement
is expected:
basyx-python-sdk/basyx/aas/model/submodel.py
Lines 749 to 752 in ab298a7
from basyx-python-sdk.
I have this classes for it (e.g. QosFlowStatus) which inherit from e.g. SubmodelElementCollection class:
class QosFlowStatus(SubmodelElementCollection):
def __init__(
self,
qfi,
qos_profile,
alternative_qos_profiles,
rrm_parameters,
id_short: NameType | None,
value: Iterable[SubmodelElement] = ...,
display_name: MultiLanguageNameType | None = None,
category: NameType | None = None,
description: MultiLanguageTextType | None = None,
parent: UniqueIdShortNamespace | None = None,
semantic_id: Reference | None = None, qualifier: Iterable[Qualifier] = ...,
extension: Iterable[Extension] = ...,
supplemental_semantic_id: Iterable[Reference] = ...,
embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...
):
When I try to add this collection to QosFlowStatusList:
class QosFlowStatusList(SubmodelElementList):
def __init__(
self,
id_short: NameType | None,
type_value_list_element: type,
value: Iterable = ...,
semantic_id_list_element: Reference | None = None,
value_type_list_element: DataTypeDefXsd | None = None,
order_relevant: bool = True,
display_name: MultiLanguageNameType | None = None,
category: NameType | None = None,
description: MultiLanguageTextType | None = None,
parent: UniqueIdShortNamespace | None = None,
semantic_id: Reference | None = None,
qualifier: Iterable[Qualifier] = ...,
extension: Iterable[Extension] = ...,
supplemental_semantic_id: Iterable[Reference] = ...,
embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ...
):
And I obtain this error (which I don´t understand):
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[4], [line 275](vscode-notebook-cell:?execution_count=4&line=275)
[273](vscode-notebook-cell:?execution_count=4&line=273) print(elemento_ref_2._type_value_list_element)
[274](vscode-notebook-cell:?execution_count=4&line=274) qos_flow_list=QosFlowStatusList(elemento_ref_2.id_short, elemento_ref_2._type_value_list_element, elemento_ref_2._value, elemento_ref_2._semantic_id_list_element, elemento_ref_2._value_type_list_element, elemento_ref_2._order_relevant, elemento_ref_2.display_name, elemento_ref_2.category, elemento_ref_2.description, elemento_ref_2.parent, elemento_ref_2.semantic_id, elemento_ref_2.qualifier, elemento_ref_2.extension, elemento_ref_2.supplemental_semantic_id, elemento_ref_2.embedded_data_specifications)
--> [275](vscode-notebook-cell:?execution_count=4&line=275) qos_flow_list.value.add(qos_flow)
[277](vscode-notebook-cell:?execution_count=4&line=277) pdu_session=PDUSessionStatus(ip_address,qos_flow_list, elemento_ref.id_short, elemento_ref.value, elemento_ref.display_name, elemento_ref.category, elemento_ref.description, elemento_ref.parent, elemento_ref.semantic_id, elemento_ref.qualifier, elemento_ref.extension, elemento_ref.supplemental_semantic_id, elemento_ref.embedded_data_specifications)
[279](vscode-notebook-cell:?execution_count=4&line=279) pdu_session_list=PDUSessionStatusList(elemento_contenido.id_short, elemento_contenido._type_value_list_element, elemento_contenido._value, elemento_contenido._semantic_id_list_element, elemento_contenido._value_type_list_element, elemento_contenido._order_relevant, elemento_contenido.display_name, elemento_contenido.category, elemento_contenido.description, elemento_contenido.parent, elemento_contenido.semantic_id, elemento_contenido.qualifier, elemento_contenido.extension, elemento_contenido.supplemental_semantic_id, elemento_contenido.embedded_data_specifications)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082), in OrderedNamespaceSet.add(self, element)
[2081](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2081) def add(self, element: _NSO):
-> [2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082) super().add(element)
[2083](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2083) self._order.append(element)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884), in NamespaceSet.add(self, element)
[1881](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1881) raise ValueError("Object has already a parent; it cannot belong to two namespaces.")
[1882](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1882) # TODO remove from current parent instead (allow moving)?
-> [1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884) self._execute_item_id_set_hook(element)
[1885](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1885) self._validate_namespace_constraints(element)
[1886](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1886) self._execute_item_add_hook(element)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1921](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1921), in NamespaceSet._execute_item_id_set_hook(self, element)
[1919](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1919) def _execute_item_id_set_hook(self, element: _NSO):
[1920](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1920) if self._item_id_set_hook is not None:
-> [1921](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1921) self._item_id_set_hook(element)
...
[624](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:624) else:
File <frozen _collections_abc>:1030, in index(self, value, start, stop)
Then I have tried to add this qos_flow
to a very simple list like that:
my_list = SubmodelElementList(
id_short="lista_1",
type_value_list_element=SubmodelElementCollection,
value_type_list_element=None # Set to None for SubmodelElementCollection
)
# Creating new SubmodelElement instances (replace SubmodelElement with the actual class)
new_element1 = SubmodelElementCollection(id_short=None)
new_element2 = SubmodelElementCollection(id_short=None)
# Adding elements to the SubmodelElementList
my_list.value.add(new_element1)
my_list.value.add(new_element2)
So now I check attributes of qos_flow
and try to add to this simple list:
qos_flow.id_short
generated_submodel_list_hack_4ecbd1f2c73f11ee8000f057a6e54ba0
Now I try to add this qos_flow
:
my_list.value.add(qos_flow)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[8], [line 1](vscode-notebook-cell:?execution_count=8&line=1)
----> [1](vscode-notebook-cell:?execution_count=8&line=1) my_list.value.add(qos_flow)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082), in OrderedNamespaceSet.add(self, element)
[2081](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2081) def add(self, element: _NSO):
-> [2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082) super().add(element)
[2083](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2083) self._order.append(element)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1881](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1881), in NamespaceSet.add(self, element)
[1879](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1879) def add(self, element: _NSO):
[1880](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1880) if element.parent is not None and element.parent is not self.parent:
-> [1881](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1881) raise ValueError("Object has already a parent; it cannot belong to two namespaces.")
[1882](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1882) # TODO remove from current parent instead (allow moving)?
[1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884) self._execute_item_id_set_hook(element)
ValueError: Object has already a parent; it cannot belong to two namespaces.
So, I try this:
qos_flow.parent=None
my_list.value.add(qos_flow)
---------------------------------------------------------------------------
AASConstraintViolation Traceback (most recent call last)
Cell In[9], [line 2](vscode-notebook-cell:?execution_count=9&line=2)
[1](vscode-notebook-cell:?execution_count=9&line=1) qos_flow.parent=None
----> [2](vscode-notebook-cell:?execution_count=9&line=2) my_list.value.add(qos_flow)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082), in OrderedNamespaceSet.add(self, element)
[2081](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2081) def add(self, element: _NSO):
-> [2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082) super().add(element)
[2083](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2083) self._order.append(element)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884), in NamespaceSet.add(self, element)
[1881](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1881) raise ValueError("Object has already a parent; it cannot belong to two namespaces.")
[1882](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1882) # TODO remove from current parent instead (allow moving)?
-> [1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884) self._execute_item_id_set_hook(element)
[1885](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1885) self._validate_namespace_constraints(element)
[1886](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1886) self._execute_item_add_hook(element)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1921](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1921), in NamespaceSet._execute_item_id_set_hook(self, element)
[1919](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1919) def _execute_item_id_set_hook(self, element: _NSO):
[1920](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1920) if self._item_id_set_hook is not None:
-> [1921](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1921) self._item_id_set_hook(element)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\submodel.py:739](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:739), in SubmodelElementList._generate_id_short(self, new)
[737](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:737) def _generate_id_short(self, new: _SE) -> None:
...
[742](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:742) # have an id_short. The alternative would be making SubmodelElementList a special kind of base.Namespace without
[743](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:743) # a unique attribute for child-elements (which contradicts the definition of a Namespace).
[744](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:744) new.id_short = "generated_submodel_list_hack_" + uuid.uuid1(clock_seq=self._uuid_seq).hex
AASConstraintViolation: Objects with an id_short may not be added to a SubmodelElementList, got QosFlowStatus[generated_submodel_list_hack_4ecbd1f2c73f11ee8000f057a6e54ba0] with id_short=generated_submodel_list_hack_4ecbd1f2c73f11ee8000f057a6e54ba0 (Constraint AASd-120)
So now I try with id_short=None:
qos_flow.id_short=None
my_list.value.add(qos_flow)
And I have found this error:
---------------------------------------------------------------------------
AASConstraintViolation Traceback (most recent call last)
Cell In[10], [line 2](vscode-notebook-cell:?execution_count=10&line=2)
[1](vscode-notebook-cell:?execution_count=10&line=1) qos_flow.id_short=None
----> [2](vscode-notebook-cell:?execution_count=10&line=2) my_list.value.add(qos_flow)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082), in OrderedNamespaceSet.add(self, element)
[2081](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2081) def add(self, element: _NSO):
-> [2082](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2082) super().add(element)
[2083](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:2083) self._order.append(element)
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1886](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1886), in NamespaceSet.add(self, element)
[1884](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1884) self._execute_item_id_set_hook(element)
[1885](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1885) self._validate_namespace_constraints(element)
-> [1886](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1886) self._execute_item_add_hook(element)
[1888](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1888) element.parent = self.parent
[1889](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1889) for key_attr_name, (backend, case_sensitive) in self._backend.items():
File [c:\Users\uwicore\anaconda3\Lib\site-packages\basyx\aas\model\base.py:1926](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1926), in NamespaceSet._execute_item_add_hook(self, element)
[1924](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1924) if self._item_add_hook is not None:
[1925](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1925) try:
-> [1926](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1926) self._item_add_hook(element, self.__iter__())
[1927](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1927) except Exception as e:
[1928](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/base.py:1928) self._execute_item_del_hook(element)
...
[770](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:770) raise base.AASConstraintViolation(107, f"If semantic_id_list_element={self.semantic_id_list_element!r} "
[771](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:771) "is specified all first level children must have the same "
[772](file:///C:/Users/uwicore/anaconda3/Lib/site-packages/basyx/aas/model/submodel.py:772) f"semantic_id, got {new!r} with semantic_id={new.semantic_id!r}")
AASConstraintViolation: All first level elements must be of the type specified in type_value_list_element=SubmodelElementCollection, got QosFlowStatus (Constraint AASd-108)
So, the last thing that I have tried is to ask if this qos_flow
is a submodelElementCollection:
if isinstance(qos_flow,SubmodelElementCollection): print("Yes, it is")
Yes, it is
So now I don´t know what can I do with this list. If you need more information to try to find the solution to this problem, let me know.
Thank you in advance.
EDIT (by @s-heppner): I took the liberty to fix the syntax in your issue. Feel free to check the text, for example by pressing "edit" yourself, so that you can learn how to write more readable issues
from basyx-python-sdk.
Related Issues (20)
- Misleading error message in case of non-existent file HOT 1
- Update `Development Status` classifier in `setup.py` HOT 1
- Integer value is not accepted for Double value type HOT 4
- aasx: Add failsafe for writing and reading AASX files HOT 1
- Convert primitive types into string when creating a property of type string HOT 2
- Logo: Change logo to the original version
- AAS with submodel/type: "ExternalReference" not supported HOT 7
- Reading published AAS Submodel Templates from aasx HOT 11
- Unable to add SubmodelElementCollection to SubmodelElementList HOT 9
- Concept Description missing from AAS (AASX-file) when External Reference is used. HOT 5
- Remove schema files from repository HOT 1
- Attaching files with spaces in the file name causes a ValueError when writing the AASX HOT 6
- Missing 'aasx-spec' document in AASX HOT 9
- RELATIONSHIP_TYPE_AASX_ORIGIN strings do not match those in the submodel templates from IDTA HOT 2
- model: Allow empty strings in SubmodelElement.value HOT 1
- How to generate unique IDs? HOT 4
- Does a property lose its reference to a concept description when reading an AASX file? HOT 6
- Log a warning if no AAS files are read within an AASX package
- aas:adapter Unable to read aasx file, because of dead links HOT 10
- convert json into aasx fails HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from basyx-python-sdk.