adapter.json, adapter.xml: Falsy Extension and Qualifier values omitted

Offen Anfängerfreundlich
#682 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 6 Tagen

@LivingLikeKrillin arbeitet bereits daran.

Seit 30.10.2026.

  • #683 von @LivingLikeKrillin — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
85/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend

Rechercherichtung

Lies sdk/basyx/aas/adapter/json/json_serialization.py und sdk/basyx/aas/adapter/xml/xml_serialization.py, mit Fokus auf _qualifier_to_json, _extension_to_json, qualifier_to_xml und extension_to_xml. Ändere den if obj.value: Guard zu if obj.value is not None: in jedem, mirroring Property serialization. Füge Round-Trip-Tests für 0, Decimal("0") und False in beiden Adaptern hinzu; erledigt bedeutet, dass falsy Werte serialize-deserialize überstehen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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"), and False are preserved in the serialized output.
  • Actual: The value is omitted from the serialized JSON/XML. During a round trip (serialize and then deserialize), the value becomes None, 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_json and _extension_to_json guard the value using if obj.value:.

In sdk/basyx/aas/adapter/xml/xml_serialization.py:

  • qualifier_to_xml and extension_to_xml guard the value using if 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.

Vorherrschende Sprache
Python
Sterne
106
Forks
67
Ø Merge
3 T. 18 Std.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus eclipse-basyx/basyx-python-sdk

Alle Issues in eclipse-basyx/basyx-python-sdk

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.