Skip to content

Commit 0017ef0

Browse files
committed
fix(core): guard the registry conflict check against a non-class
- a fetch can register a class while the title names a non-class - issubclass() in the conflict warning then raised TypeError - tie the non-class log assertion to the loaded page's title
1 parent 0ea247c commit 0017ef0

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎src/osw/core.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,9 +1333,13 @@ def load_entity(
13331333
# generated_cls, e.g. a controller
13341334
# that inherits the category IRI:
13351335
# the case the guard above expects,
1336-
# not a conflict
1337-
and not issubclass(
1338-
conflicting_cls, generated_cls
1336+
# not a conflict. A fetch can leave
1337+
# a non-class under the schema title.
1338+
and not (
1339+
isinstance(generated_cls, type)
1340+
and issubclass(
1341+
conflicting_cls, generated_cls
1342+
)
13391343
)
13401344
):
13411345
_logger.warning(

‎tests/test_load_entity_registered_class.py‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,37 @@ def test_load_entity_logs_a_schema_title_that_names_no_class(caplog):
405405
try:
406406
_load_single_category_page(category, cls_name, "B")
407407
assert any(
408-
"Error creating entity from page" in record.message
408+
"Error creating entity from page Item:OSWNonClassB" in record.message
409409
for record in caplog.records
410410
)
411411
finally:
412412
delattr(model, cls_name)
413+
414+
415+
def test_load_entity_logs_a_fetch_that_leaves_no_class_under_the_title(
416+
monkeypatch, caplog
417+
):
418+
"""fetch_schema() can register a class for the category while the schema
419+
title still names a non-class attribute of osw.model.entity. The registry
420+
conflict check must not call issubclass() on that value; the failed
421+
construction is logged, as on main."""
422+
category = "Category:OSWNonClassFetched000000000000000000000"
423+
cls_name = "NonClassAttributeC"
424+
assert oold_type_registry.get(category) is None
425+
fetched_cls = make_isolated_cls("NonClassFetched")
426+
427+
def fake_fetch_schema(self, fetchSchemaParam=None):
428+
setattr(model, cls_name, "not a class")
429+
oold_type_registry[category] = fetched_cls
430+
431+
monkeypatch.setattr(OSW, "fetch_schema", fake_fetch_schema)
432+
try:
433+
_load_single_category_page(category, cls_name, "C")
434+
assert any(
435+
"Error creating entity from page Item:OSWNonClassC" in record.message
436+
for record in caplog.records
437+
)
438+
finally:
439+
if hasattr(model, cls_name):
440+
delattr(model, cls_name)
441+
oold_type_registry.pop(category, None)

0 commit comments

Comments
 (0)