Commit 871e4ec5 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

mod: backout the removal of construction_mode

parent 727b5e6d9f13
Pipeline #10080 passed with stage
in 1 minute and 25 seconds
......@@ -171,7 +171,7 @@ class SchemaLoader:
else:
self._load_module_names(module_names)
schema = self.schema_class(name or "NoName")
schema = self.schema_class(name or "NoName", construction_mode=construction_mode)
# if construction_mode != "strict" handle errors
try:
......
......@@ -1395,9 +1395,14 @@ class Schema:
# only defining here to prevent checkers from complaining
info = warning = error = critical = exception = debug = lambda message, *a, **kw: None
def __init__(self, name: str) -> None:
def __init__(self, name: str, construction_mode: str = "strict") -> None:
super(Schema, self).__init__()
self.name = name
# with construction_mode != 'strict', no error when trying to add a
# relation using an undefined entity type, simply log the error
# right now, construction_mode != 'strict' is only used by migractions
self.construction_mode = construction_mode
self._entities: Dict = {}
self._relations: Dict = {}
......@@ -1519,26 +1524,34 @@ class Schema:
except KeyError:
# returns here are to break the function but don't return anything
# shouldn't it raise instead?
raise BadSchemaDefinition(
f"using unknown relation type '{relation_type}' in {relation_definition}"
)
self._building_error(f"using unknown relation type in {relation_definition}")
return None
try:
subject_schema = self.entity_schema_for(relation_definition.subject)
except KeyError:
raise BadSchemaDefinition(
f"using unknown type '{relation_definition.subject}' in relation {relation_type}"
self._building_error(
f"using unknown type {repr(relation_definition.subject)} in relation "
f"{relation_type}"
)
return None
try:
object_schema = self.entity_schema_for(relation_definition.object)
except KeyError:
raise BadSchemaDefinition(
f"using unknown type '{relation_definition.object}' in relation {relation_type}"
self._building_error(
f"using unknown type {repr(relation_definition.object)} in relation {relation_type}"
)
return None
return relation_schema.update(subject_schema, object_schema, relation_definition)
def _building_error(self, message, *args) -> None:
if self.construction_mode == "strict":
raise BadSchemaDefinition(message % args)
self.critical(message, *args)
@deprecation.argument_renamed(old_name="rtype", new_name="relation_type")
@deprecation.argument_renamed(old_name="subjtype", new_name="subject_type")
@deprecation.argument_renamed(old_name="objtype", new_name="object_type")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment