Skip to content

Commit c116199

Browse files
committed
fix(core): do not warn when a registered subclass was set aside
- the subclass guard keeps the specialization in the registry slot - the conflict warning then compared it with the canonical class and fired - this happened on every WikiFile load, with a message that was untrue
1 parent 4ee1e09 commit c116199

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/osw/core.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,12 @@ def load_entity(
13271327
if (
13281328
conflicting_cls is not None
13291329
and conflicting_cls is not generated_cls
1330+
# a specialization of generated_cls was
1331+
# already set aside above; it still
1332+
# holds the slot and nothing claimed it
1333+
and not issubclass(
1334+
conflicting_cls, generated_cls
1335+
)
13301336
):
13311337
_logger.warning(
13321338
f"Class '{generated_cls}' generated for "

‎tests/test_load_entity_registered_class.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,16 @@ def test_load_entity_falls_back_to_generated_class_when_nothing_registered():
171171
delattr(model, cls_name)
172172

173173

174-
def test_load_entity_ignores_a_registered_subclass_of_the_model_class():
174+
def test_load_entity_ignores_a_registered_subclass_of_the_model_class(caplog):
175175
"""osw's own controllers and result wrappers (WikiFileController,
176176
UploadFileResult, ...) inherit the category IRI of the model class they
177177
extend, and oold's registry keeps whichever class was defined last. Such a
178178
specialization needs fields a plain page does not carry, so load_entity()
179179
must fall back to the canonical class in osw.model.entity.
180+
181+
This is the expected case on every WikiFile load, so it must not raise the
182+
registry conflict warning: nothing claims the slot, it still holds the
183+
specialization.
180184
"""
181185
category = "Category:OSWSubclassTest000000000000000000000000"
182186
cls_name = "SubclassTestBase"
@@ -219,6 +223,10 @@ def test_load_entity_ignores_a_registered_subclass_of_the_model_class():
219223
)
220224

221225
assert type(result.entities[0]) is base_cls
226+
assert not any(
227+
"claims the oold type registry slot" in record.message
228+
for record in caplog.records
229+
)
222230
finally:
223231
delattr(model, cls_name)
224232
oold_type_registry.pop(category, None)

0 commit comments

Comments
 (0)