Skip to content

Commit f195a97

Browse files
committed
fix: detect CharacteristicType from the opensemantic packages too
- entities built from opensemantic.core.v1 derive from its CharacteristicType, not the one in osw.model.entity, so the generated schema was written flat instead of into $defs.generated - tolerate entity models without a meta field when tagging change ids
1 parent a906f87 commit f195a97

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

‎src/osw/core.py‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
from pyld import jsonld
4040

4141
import osw.model.entity as model
42+
43+
try:
44+
# Characteristics of the released opensemantic packages derive from this
45+
# class, not from the one in osw.model.entity.
46+
from opensemantic.core.v1 import (
47+
CharacteristicType as _OpensemanticCharacteristicType,
48+
)
49+
except ImportError: # pragma: no cover - optional dependency
50+
_OpensemanticCharacteristicType = None
4251
from osw.defaults import params as default_params
4352
from osw.utils.code_postprocessing import (
4453
remove_constraints_from_forward_refs,
@@ -1788,12 +1797,15 @@ def __init__(self, **data):
17881797
if self.change_id is None:
17891798
self.change_id = str(uuid4())
17901799
for entity in self.entities:
1791-
if getattr(entity, "meta", None) is None:
1792-
entity.meta = model.Meta()
1793-
if entity.meta.change_id is None:
1794-
entity.meta.change_id = []
1795-
if self.change_id not in entity.meta.change_id:
1796-
entity.meta.change_id.append(self.change_id)
1800+
try:
1801+
if getattr(entity, "meta", None) is None:
1802+
entity.meta = model.Meta()
1803+
if entity.meta.change_id is None:
1804+
entity.meta.change_id = []
1805+
if self.change_id not in entity.meta.change_id:
1806+
entity.meta.change_id.append(self.change_id)
1807+
except (ValueError, AttributeError):
1808+
pass # entity model doesn't have meta field
17971809
if len(self.entities) > 5 and self.parallel is None:
17981810
self.parallel = True
17991811
if self.parallel is None:
@@ -2058,10 +2070,18 @@ def store_entity_(
20582070

20592071
mode = AggregateGeneratedSchemasParamMode.ROOT_LEVEL
20602072
# Put generated schema in definitions section,
2061-
# currently only enabled for Characteristics
2062-
if hasattr(model, "CharacteristicType") and isinstance(
2063-
entity_, model.CharacteristicType
2064-
):
2073+
# currently only enabled for Characteristics. The class is
2074+
# either the locally generated one or the one shipped by the
2075+
# opensemantic packages, depending on where the model is from.
2076+
characteristic_types = tuple(
2077+
t
2078+
for t in (
2079+
getattr(model, "CharacteristicType", None),
2080+
_OpensemanticCharacteristicType,
2081+
)
2082+
if t is not None
2083+
)
2084+
if characteristic_types and isinstance(entity_, characteristic_types):
20652085
mode = AggregateGeneratedSchemasParamMode.DEFINITIONS_SECTION
20662086

20672087
new_schema = aggregate_generated_schemas(

0 commit comments

Comments
 (0)