Skip to content
Snippets Groups Projects
Commit 6347bb41ca25 authored by Elodie Thiéblin's avatar Elodie Thiéblin
Browse files

refactor: handle error result in get_entity_from_uri

parent f310c4832066
No related branches found
No related tags found
1 merge request!21Topic/default/rdf
...@@ -48,7 +48,14 @@ ...@@ -48,7 +48,14 @@
try: try:
return cnx.execute(rql_query, {"uri": entity_uri}).one() return cnx.execute(rql_query, {"uri": entity_uri}).one()
except NoResultError: except NoResultError:
print("warn: no cubicweb entity for ", entity_uri) print("warn: no cubicweb entity for ", entity_uri, " skipping addition")
return None
except MultipleResultsError:
print(
"warn: multiple cubicweb entities for ",
entity_uri,
" skipping addition",
)
return None return None
def get_schema_as_dict(self, repo): def get_schema_as_dict(self, repo):
...@@ -87,18 +94,8 @@ ...@@ -87,18 +94,8 @@
temp_labels = [] temp_labels = []
# Get entity type from equivalent_uri # Get entity type from equivalent_uri
try: entity_type = self.get_entity_from_uri(cnx, class_uri, "CWEType")
entity_type = self.get_entity_from_uri(cnx, class_uri, "CWEType") if entity_type is None:
except NoResultError:
print(
f"Did not import {instance_uri} as {class_uri} is unknown in the schema."
)
continue
except MultipleResultsError:
print(
f"Did not import {instance_uri} as {class_uri} because"
" multiple types are possible."
)
continue continue
# Get entity attribute # Get entity attribute
...@@ -108,6 +105,8 @@ ...@@ -108,6 +105,8 @@
external_uri = cnx.create_entity("ExternalUri", uri=instance_uri) external_uri = cnx.create_entity("ExternalUri", uri=instance_uri)
temp_attributes = {"equivalent_uri": external_uri} temp_attributes = {"equivalent_uri": external_uri}
for predicate_uri, object_value in g.predicate_objects(instance_uri): for predicate_uri, object_value in g.predicate_objects(instance_uri):
if predicate_uri == RDF.type:
continue
relation_type = None relation_type = None
try: try:
relation_type = self.get_entity_from_uri( relation_type = self.get_entity_from_uri(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment