Skip to content

Commit

Permalink
fix(utils): make rdfimport parent model check more loose
Browse files Browse the repository at this point in the history
The check was designed to check the type of the passed object is a
sublcass of the superclass, but we usually pass a class and not an
instance, so lets also check the class itself.
  • Loading branch information
b1rger committed Jul 22, 2024
1 parent e9dde41 commit 349534c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apis_core/utils/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def definition_matches_model(definition: str, model: object) -> bool:
module, cls = definition.get("superclass").rsplit(".", 1)
module = importlib.import_module(module)
parent = getattr(module, cls)
if issubclass(type(model), parent):
if issubclass(type(model), parent) or issubclass(model, parent):
return True
except Exception as e:
logger.error("superclass %s led to: %s", definition.get("superclass"), e)
Expand Down
7 changes: 3 additions & 4 deletions apis_core/utils/test_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ class Meta:
class RdfTest(TestCase):
def test_get_definition_from_dict_place_from_geonames(self):
achensee = {
"kind": "https://www.geonames.org/ontology#P.PPL",
"lat": "47.5",
"long": "11.7",
"name": "Achensee",
"parent": "https://sws.geonames.org/2782113/",
"label": "Achensee",
}
# https://www.geonames.org/2783029/achensee.html
uri = str(testdata / "achensee.rdf")
Expand All @@ -55,7 +53,8 @@ def test_get_definition_from_dict_place_from_dnb(self):

def test_get_definition_from_dict_person_from_dnb(self):
pierre = {
"name": "Ramus,Pierre",
"forename": "Pierre",
"surname": "Ramus",
"profession": "https://d-nb.info/gnd/4053309-8",
"date_of_birth": "1882-04-15",
"date_of_death": "1942",
Expand Down

0 comments on commit 349534c

Please sign in to comment.