Repository navigation
load_entity raises instead of logging when a category page has no usable schema title #202
Description
OSW.load_entity reads the schema title outside the block that handles a failure per page. One unusable category page therefore ends the whole call, and the remaining titles are not loaded.
Lines 1355 to 1372 in d7f0116
| for category in jsondata["type"]: | |
| schema = ( | |
| self.site | |
| .get_page( | |
| WtSite.GetPageParam( | |
| titles=[category], offline_pages=param.offline_pages | |
| ) | |
| ) | |
| .pages[0] | |
| .get_slot_content("jsonschema") | |
| ) | |
| schemas.append(schema) | |
| # generate model if not already exists | |
| cls_name: str = schema["title"] | |
| # If a schema_to_use is provided, we do not need to check if | |
| # the model exists | |
| if not param.model_to_use: | |
| if not hasattr(model, cls_name): |
for category in jsondata["type"]:
schema = (
self.site.get_page(...).pages[0].get_slot_content("jsonschema")
)
schemas.append(schema)
cls_name: str = schema["title"] # line 1368
if not param.model_to_use:
if not hasattr(model, cls_name): # line 1372Three inputs raise here:
| Input | Exception |
|---|---|
the category page has no jsonschema slot, so get_slot_content returns None |
TypeError: 'NoneType' object is not subscriptable (line 1368) |
the schema has no title key |
KeyError: 'title' (line 1368) |
title is present but not a string |
TypeError: attribute name must be string (line 1372) |
get_slot_content returns None for a slot the page does not have:
Lines 1700 to 1701 in d7f0116
| if slot_key not in self._slots: | |
| return None |
A page reaches this state when its type names a page that does not exist, is not a category, or has an empty jsonschema slot.
Expected
Report the fault for that page and continue with the next one, as the rest of the loop does.
- The entity construction below catches every exception, logs it with the page title, and the loop continues:
Lines 1407 to 1408 in d7f0116
except Exception as e: _logger.error(f"Error creating entity from page {page.title}: {e}") - The missing-model case four lines lower does the same: it logs with
_logger.error, setsschemas_fetched = Falseand the loop continues with the next page:
Lines 1381 to 1388 in d7f0116
if not hasattr(model, cls_name): schemas_fetched = False _logger.error( f"Model {cls_name} not found. Schema {category} " f"needs to be fetched first." ) if not schemas_fetched: continue
Today the exception passes through the try at line 1340, whose finally only restores the cache state, and leaves load_entity. The message names neither the page nor the category, so the caller cannot tell which page is wrong.
Notes
- Present on main at
d7f0116. - fix(core): prefer a registered class over a generated one #166 changes the same block and does not change this behaviour. The case was found while testing that PR and left out of it, because it is independent of the subject of that PR.
Activity