Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions src/osw/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
from pyld import jsonld

import osw.model.entity as model

try:
# Characteristics of the released opensemantic packages derive from this
# class, not from the one in osw.model.entity.
from opensemantic.core.v1 import (
CharacteristicType as _OpensemanticCharacteristicType,
)
except ImportError: # pragma: no cover - optional dependency
_OpensemanticCharacteristicType = None
from osw.defaults import params as default_params
from osw.utils.code_postprocessing import (
remove_constraints_from_forward_refs,
Expand Down Expand Up @@ -1788,12 +1797,15 @@ def __init__(self, **data):
if self.change_id is None:
self.change_id = str(uuid4())
for entity in self.entities:
if getattr(entity, "meta", None) is None:
entity.meta = model.Meta()
if entity.meta.change_id is None:
entity.meta.change_id = []
if self.change_id not in entity.meta.change_id:
entity.meta.change_id.append(self.change_id)
try:
if getattr(entity, "meta", None) is None:
entity.meta = model.Meta()
if entity.meta.change_id is None:
entity.meta.change_id = []
if self.change_id not in entity.meta.change_id:
entity.meta.change_id.append(self.change_id)
except (ValueError, AttributeError):
pass # entity model doesn't have meta field
if len(self.entities) > 5 and self.parallel is None:
self.parallel = True
if self.parallel is None:
Expand Down Expand Up @@ -2058,10 +2070,18 @@ def store_entity_(

mode = AggregateGeneratedSchemasParamMode.ROOT_LEVEL
# Put generated schema in definitions section,
# currently only enabled for Characteristics
if hasattr(model, "CharacteristicType") and isinstance(
entity_, model.CharacteristicType
):
# currently only enabled for Characteristics. The class is
# either the locally generated one or the one shipped by the
# opensemantic packages, depending on where the model is from.
characteristic_types = tuple(
t
for t in (
getattr(model, "CharacteristicType", None),
_OpensemanticCharacteristicType,
)
if t is not None
)
if characteristic_types and isinstance(entity_, characteristic_types):
mode = AggregateGeneratedSchemasParamMode.DEFINITIONS_SECTION

new_schema = aggregate_generated_schemas(
Expand Down
Loading