Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
yams
Commits
5b2662c9a342
Commit
871e4ec5
authored
Jun 25, 2020
by
Laurent Peuch
Browse files
mod: backout the removal of construction_mode
parent
727b5e6d9f13
Pipeline
#10080
passed with stage
in 1 minute and 25 seconds
Changes
2
Pipelines
5
Hide whitespace changes
Inline
Side-by-side
yams/reader.py
View file @
5b2662c9
...
...
@@ -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
:
...
...
yams/schema.py
View file @
5b2662c9
...
...
@@ -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"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment