@@ -1254,101 +1254,113 @@ def load_entity(
12541254 remove_empty (jsondata )
12551255 if jsondata :
12561256 for category in jsondata ["type" ]:
1257- schema = (
1258- self .site
1259- .get_page (
1260- WtSite .GetPageParam (
1261- titles = [category ], offline_pages = param .offline_pages
1257+ # one unusable category must not end the whole call
1258+ try :
1259+ schema = (
1260+ self .site
1261+ .get_page (
1262+ WtSite .GetPageParam (
1263+ titles = [category ],
1264+ offline_pages = param .offline_pages ,
1265+ )
12621266 )
1267+ .pages [0 ]
1268+ .get_slot_content ("jsonschema" )
12631269 )
1264- .pages [0 ]
1265- .get_slot_content ("jsonschema" )
1266- )
1267- schemas .append (schema )
1268- # generate model if not already exists
1269- cls_name : str = schema ["title" ]
1270- # If a schema_to_use is provided, we do not need to check if
1271- # the model exists
1272- if not param .model_to_use :
1273- # Prefer a class already registered for this category
1274- # IRI (e.g. a packaged model class) over compiling a
1275- # new one. Compiling one anyway would take over the
1276- # oold type registry entry for this category and hide
1277- # the packaged class' typed fields/helpers.
1278- registered_cls = oold_type_registry .get (category )
1279- # Controllers and result wrappers (e.g.
1280- # WikiFileController, UploadFileResult) inherit
1281- # their category IRI from the model class they
1282- # extend, and the registry keeps whichever class
1283- # was defined last. Such a specialization asks for
1284- # fields a plain page's jsondata does not carry, so
1285- # prefer the canonical class from osw.model.entity
1286- # over a subclass of it.
1287- canonical_cls = getattr (model , cls_name , None )
1288- if (
1289- registered_cls is not None
1290- # the schema title can also name a module
1291- # attribute that is not a class
1292- and isinstance (canonical_cls , type )
1293- and registered_cls is not canonical_cls
1294- and issubclass (registered_cls , canonical_cls )
1295- ):
1296- _logger .debug (
1297- f"Ignoring '{ registered_cls } ' registered for "
1298- f"category '{ category } ': it specializes "
1299- f"'{ canonical_cls } ', which is used instead."
1300- )
1301- registered_cls = None
1302- if registered_cls is not None :
1303- category_to_cls [category ] = registered_cls
1304- else :
1305- if not hasattr (model , cls_name ):
1306- if param .autofetch_schema :
1307- self .fetch_schema (
1308- OSW .FetchSchemaParam (
1309- schema_title = category ,
1310- mode = "append" ,
1311- offline_pages = param .offline_pages ,
1312- )
1313- )
1314- if not hasattr (model , cls_name ):
1315- schemas_fetched = False
1316- _logger .error (
1317- f"Model { cls_name } not found. Schema "
1318- f"{ category } needs to be fetched first."
1270+ schemas .append (schema )
1271+ # generate model if not already exists
1272+ cls_name : str = schema ["title" ]
1273+ # If a schema_to_use is provided, we do not need to check if
1274+ # the model exists
1275+ if not param .model_to_use :
1276+ # Prefer a class already registered for this category
1277+ # IRI (e.g. a packaged model class) over compiling a
1278+ # new one. Compiling one anyway would take over the
1279+ # oold type registry entry for this category and hide
1280+ # the packaged class' typed fields/helpers.
1281+ registered_cls = oold_type_registry .get (category )
1282+ # Controllers and result wrappers (e.g.
1283+ # WikiFileController, UploadFileResult) inherit
1284+ # their category IRI from the model class they
1285+ # extend, and the registry keeps whichever class
1286+ # was defined last. Such a specialization asks for
1287+ # fields a plain page's jsondata does not carry, so
1288+ # prefer the canonical class from osw.model.entity
1289+ # over a subclass of it.
1290+ canonical_cls = getattr (model , cls_name , None )
1291+ if (
1292+ registered_cls is not None
1293+ # the schema title can also name a module
1294+ # attribute that is not a class
1295+ and isinstance (canonical_cls , type )
1296+ and registered_cls is not canonical_cls
1297+ and issubclass (registered_cls , canonical_cls )
1298+ ):
1299+ _logger .debug (
1300+ f"Ignoring '{ registered_cls } ' registered for "
1301+ f"category '{ category } ': it specializes "
1302+ f"'{ canonical_cls } ', which is used instead."
13191303 )
1304+ registered_cls = None
1305+ if registered_cls is not None :
1306+ category_to_cls [category ] = registered_cls
13201307 else :
1321- generated_cls = getattr (model , cls_name )
1322- # The class we are about to use may have just
1323- # claimed (or may already hold) the registry
1324- # slot for this category. If a different class
1325- # is registered for it, someone's registration
1326- # was silently overwritten - do not raise, but
1327- # make sure this does not pass silently.
1328- conflicting_cls = oold_type_registry .get (category )
1329- if (
1330- conflicting_cls is not None
1331- and conflicting_cls is not generated_cls
1332- # the slot holder specializes
1333- # generated_cls, e.g. a controller
1334- # that inherits the category IRI:
1335- # the case the guard above expects,
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
1308+ if not hasattr (model , cls_name ):
1309+ if param .autofetch_schema :
1310+ self .fetch_schema (
1311+ OSW .FetchSchemaParam (
1312+ schema_title = category ,
1313+ mode = "append" ,
1314+ offline_pages = param .offline_pages ,
1315+ )
13421316 )
1317+ if not hasattr (model , cls_name ):
1318+ schemas_fetched = False
1319+ _logger .error (
1320+ f"Model { cls_name } not found. Schema "
1321+ f"{ category } needs to be fetched first."
13431322 )
1344- ):
1345- _logger .warning (
1346- f"Class '{ generated_cls } ' generated for "
1347- f"category '{ category } ' claims the oold "
1348- f"type registry slot already held by a "
1349- f"different class '{ conflicting_cls } '."
1323+ else :
1324+ generated_cls = getattr (model , cls_name )
1325+ # The class we are about to use may have just
1326+ # claimed (or may already hold) the registry
1327+ # slot for this category. If a different class
1328+ # is registered for it, someone's registration
1329+ # was silently overwritten - do not raise, but
1330+ # make sure this does not pass silently.
1331+ conflicting_cls = oold_type_registry .get (
1332+ category
13501333 )
1351- category_to_cls [category ] = generated_cls
1334+ if (
1335+ conflicting_cls is not None
1336+ and conflicting_cls is not generated_cls
1337+ # the slot holder specializes
1338+ # generated_cls, e.g. a controller
1339+ # that inherits the category IRI:
1340+ # the case the guard above expects,
1341+ # not a conflict. A fetch can leave
1342+ # a non-class under the schema title.
1343+ and not (
1344+ isinstance (generated_cls , type )
1345+ and issubclass (
1346+ conflicting_cls , generated_cls
1347+ )
1348+ )
1349+ ):
1350+ _logger .warning (
1351+ f"Class '{ generated_cls } ' generated for "
1352+ f"category '{ category } ' claims the oold "
1353+ f"type registry slot already held by a "
1354+ f"different class '{ conflicting_cls } '."
1355+ )
1356+ category_to_cls [category ] = generated_cls
1357+ except Exception as e :
1358+ schemas_fetched = False
1359+ _logger .error (
1360+ f"Error reading the schema of category "
1361+ f"{ category } for page { page .title } : { e } "
1362+ )
1363+ continue
13521364 if not schemas_fetched :
13531365 continue
13541366 # fetch_schema() reloads osw.model.entity, which replaces every
0 commit comments