adapter.json, adapter.xml: Falsy Extension and Qualifier values omitted
维护者通常 1 天内回复
评估
调研方向
阅读 sdk/basyx/aas/adapter/json/json_serialization.py 和 sdk/basyx/aas/adapter/xml/xml_serialization.py,重点关注 _qualifier_to_json、_extension_to_json、qualifier_to_xml 和 extension_to_xml。将每个文件中的 if obj.value: 守卫改为 if obj.value is not None:,mirroring Property serialization。在两个适配器中为 0、Decimal("0") 和 False 添加往返测试;done 表示 falsy 值能在 serialize-deserialize 中存活。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 107
- 派生
- 61
- 平均合并
- 1 小时 9 分钟
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
eclipse-basyx/basyx-python-sdk 的其他 Issue
-
server: XML responses contain `cursor="None"` on the last page可能已有人在做 @qiaobochi040726-source 于 14 天前认领。 未关闭bug good-first-issue server
难度 2/5 1-3 小时 新手友好度 82/100
eclipse-basyx/basyx-python-sdk#673 ·
维护者通常 1 天内回复
-
adapter.aasx: Failsafe writer adds duplicate parts for conflicting files可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug good-first-issue sdk
难度 2/5 1-3 小时 新手友好度 85/100
eclipse-basyx/basyx-python-sdk#671 ·
维护者通常 1 天内回复
-
enhancement good-first-issue server
难度 2/5 1-3 小时 新手友好度 80/100
eclipse-basyx/basyx-python-sdk#670 ·
维护者通常 1 天内回复
-
adapter.aasx: Missing supplementary file aborts reading with failsafe可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug good-first-issue sdk
难度 2/5 1-3 小时 新手友好度 76/100
eclipse-basyx/basyx-python-sdk#665 ·
维护者通常 1 天内回复
-
bug server
难度 2/5 1-3 小时 新手友好度 76/100
eclipse-basyx/basyx-python-sdk#663 ·
维护者通常 1 天内回复
查看 eclipse-basyx/basyx-python-sdk 的全部 Issue
相似的 Issue
-
community enhancement good first issue
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
Hochfrequenz/sapgui.mcp#1039 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
didi/helixharness#18 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
dataforgoodfr/democracy-watch#46 · 1 个 reaction ·