adapter.json, adapter.xml: Falsy Extension and Qualifier values omitted
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
Direzione di ricerca
Leggi sdk/basyx/aas/adapter/json/json_serialization.py e sdk/basyx/aas/adapter/xml/xml_serialization.py, concentrandoti su _qualifier_to_json, _extension_to_json, qualifier_to_xml ed extension_to_xml. Cambia la guard if obj.value: in if obj.value is not None: in ciascuno, mirroring Property serialization. Aggiungi test di round-trip per 0, Decimal("0") e False in entrambi gli adapter; done significa che i valori falsy sopravvivono a serialize-deserialize.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
In both adapter.json and adapter.xml, when an Extension or Qualifier has a value that evaluates to falsy in Python—such as integer 0, Decimal("0"), or False—the serializers omit the value field or attribute entirely. Non-falsy values (such as 1) are serialized as expected.
This was discovered while validating AAS JSON environments generated by an external tool, where an Extension with an xs:decimal value of "0" lost its value after being re-serialized by BaSyx.
This behavior was observed in basyx-python-sdk 2.1.0 (from PyPI) and verified on the current develop branch.
Expected vs. Actual Behaviour
- Expected: Falsy values such as
0,Decimal("0"), andFalseare preserved in the serialized output. - Actual: The
valueis omitted from the serialized JSON/XML. During a round trip (serialize and then deserialize), the value becomesNone, resulting in data loss. The deserializers already parse"0"correctly if the value is present.
Technical Details & Root Cause
In sdk/basyx/aas/adapter/json/json_serialization.py:
_qualifier_to_jsonand_extension_to_jsonguard the value usingif obj.value:.
In sdk/basyx/aas/adapter/xml/xml_serialization.py:
qualifier_to_xmlandextension_to_xmlguard the value usingif obj.value:.
Because 0, Decimal("0"), and False evaluate to False in Python boolean evaluation, the value is not written. For comparison, Property serialization already uses if obj.value is not None:.
Reproduction
import io, json
from basyx.aas import model
from basyx.aas.adapter import json as aas_json
sm = model.Submodel(
"https://example.org/sm",
extension=[model.Extension("e", value_type=model.datatypes.Int, value=0)],
qualifier=[model.Qualifier("q", value_type=model.datatypes.Int, value=0)],
)
buf = io.StringIO()
aas_json.write_aas_json_file(buf, model.DictIdentifiableStore([sm]))
print(json.loads(buf.getvalue())["submodels"][0]["extensions"])
# [{'valueType': 'xs:int', 'name': 'e'}] -- no "value"
The qualifier output also lacks the "value" field. The XML adapter exhibits the same behavior.
Suggested Fix
Update _qualifier_to_json, _extension_to_json, qualifier_to_xml, and extension_to_xml to check if obj.value is not None:, matching the implementation in Property.
A pull request containing this fix alongside round-trip tests for 0, Decimal("0"), and False in both adapters will be submitted and reference this issue.
- Lingua principale
- Python
- Stelle
- 107
- Fork
- 61
- Merge medio
- 1h 9m
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di eclipse-basyx/basyx-python-sdk
-
server: XML responses contain `cursor="None"` on the last pageForse già presa @qiaobochi040726-source l’ha presa 14 giorni fa. Apertabug good-first-issue server
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
eclipse-basyx/basyx-python-sdk#673 ·
I maintainer di solito rispondono entro 1 giorno
-
adapter.aasx: Failsafe writer adds duplicate parts for conflicting filesForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug good-first-issue sdk
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
eclipse-basyx/basyx-python-sdk#671 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good-first-issue server
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
eclipse-basyx/basyx-python-sdk#670 ·
I maintainer di solito rispondono entro 1 giorno
-
adapter.aasx: Missing supplementary file aborts reading with failsafeForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug good-first-issue sdk
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
eclipse-basyx/basyx-python-sdk#665 ·
I maintainer di solito rispondono entro 1 giorno
-
bug server
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
eclipse-basyx/basyx-python-sdk#663 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di eclipse-basyx/basyx-python-sdk
Issue simili
-
community enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
Hochfrequenz/sapgui.mcp#1039 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
didi/helixharness#18 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
dataforgoodfr/democracy-watch#46 · 1 reazione ·