@@ -1440,101 +1440,113 @@ def load_entity(
14401440 remove_empty (jsondata )
14411441 if jsondata :
14421442 for category in jsondata ["type" ]:
1443- schema = (
1444- self .site
1445- .get_page (
1446- WtSite .GetPageParam (
1447- titles = [category ], offline_pages = param .offline_pages
1443+ # one unusable category must not end the whole call
1444+ try :
1445+ schema = (
1446+ self .site
1447+ .get_page (
1448+ WtSite .GetPageParam (
1449+ titles = [category ],
1450+ offline_pages = param .offline_pages ,
1451+ )
14481452 )
1453+ .pages [0 ]
1454+ .get_slot_content ("jsonschema" )
14491455 )
1450- .pages [0 ]
1451- .get_slot_content ("jsonschema" )
1452- )
1453- schemas .append (schema )
1454- # generate model if not already exists
1455- cls_name : str = schema ["title" ]
1456- # If a schema_to_use is provided, we do not need to check if
1457- # the model exists
1458- if not param .model_to_use :
1459- # Prefer a class already registered for this category
1460- # IRI (e.g. a packaged model class) over compiling a
1461- # new one. Compiling one anyway would take over the
1462- # oold type registry entry for this category and hide
1463- # the packaged class' typed fields/helpers.
1464- registered_cls = oold_type_registry .get (category )
1465- # Controllers and result wrappers (e.g.
1466- # WikiFileController, UploadFileResult) inherit
1467- # their category IRI from the model class they
1468- # extend, and the registry keeps whichever class
1469- # was defined last. Such a specialization asks for
1470- # fields a plain page's jsondata does not carry, so
1471- # prefer the canonical class from osw.model.entity
1472- # over a subclass of it.
1473- canonical_cls = getattr (model , cls_name , None )
1474- if (
1475- registered_cls is not None
1476- # the schema title can also name a module
1477- # attribute that is not a class
1478- and isinstance (canonical_cls , type )
1479- and registered_cls is not canonical_cls
1480- and issubclass (registered_cls , canonical_cls )
1481- ):
1482- _logger .debug (
1483- f"Ignoring '{ registered_cls } ' registered for "
1484- f"category '{ category } ': it specializes "
1485- f"'{ canonical_cls } ', which is used instead."
1486- )
1487- registered_cls = None
1488- if registered_cls is not None :
1489- category_to_cls [category ] = registered_cls
1490- else :
1491- if not hasattr (model , cls_name ):
1492- if param .autofetch_schema :
1493- self .fetch_schema (
1494- OSW .FetchSchemaParam (
1495- schema_title = category ,
1496- mode = "append" ,
1497- offline_pages = param .offline_pages ,
1498- )
1499- )
1500- if not hasattr (model , cls_name ):
1501- schemas_fetched = False
1502- _logger .error (
1503- f"Model { cls_name } not found. Schema "
1504- f"{ category } needs to be fetched first."
1456+ schemas .append (schema )
1457+ # generate model if not already exists
1458+ cls_name : str = schema ["title" ]
1459+ # If a schema_to_use is provided, we do not need to check if
1460+ # the model exists
1461+ if not param .model_to_use :
1462+ # Prefer a class already registered for this category
1463+ # IRI (e.g. a packaged model class) over compiling a
1464+ # new one. Compiling one anyway would take over the
1465+ # oold type registry entry for this category and hide
1466+ # the packaged class' typed fields/helpers.
1467+ registered_cls = oold_type_registry .get (category )
1468+ # Controllers and result wrappers (e.g.
1469+ # WikiFileController, UploadFileResult) inherit
1470+ # their category IRI from the model class they
1471+ # extend, and the registry keeps whichever class
1472+ # was defined last. Such a specialization asks for
1473+ # fields a plain page's jsondata does not carry, so
1474+ # prefer the canonical class from osw.model.entity
1475+ # over a subclass of it.
1476+ canonical_cls = getattr (model , cls_name , None )
1477+ if (
1478+ registered_cls is not None
1479+ # the schema title can also name a module
1480+ # attribute that is not a class
1481+ and isinstance (canonical_cls , type )
1482+ and registered_cls is not canonical_cls
1483+ and issubclass (registered_cls , canonical_cls )
1484+ ):
1485+ _logger .debug (
1486+ f"Ignoring '{ registered_cls } ' registered for "
1487+ f"category '{ category } ': it specializes "
1488+ f"'{ canonical_cls } ', which is used instead."
15051489 )
1490+ registered_cls = None
1491+ if registered_cls is not None :
1492+ category_to_cls [category ] = registered_cls
15061493 else :
1507- generated_cls = getattr (model , cls_name )
1508- # The class we are about to use may have just
1509- # claimed (or may already hold) the registry
1510- # slot for this category. If a different class
1511- # is registered for it, someone's registration
1512- # was silently overwritten - do not raise, but
1513- # make sure this does not pass silently.
1514- conflicting_cls = oold_type_registry .get (category )
1515- if (
1516- conflicting_cls is not None
1517- and conflicting_cls is not generated_cls
1518- # the slot holder specializes
1519- # generated_cls, e.g. a controller
1520- # that inherits the category IRI:
1521- # the case the guard above expects,
1522- # not a conflict. A fetch can leave
1523- # a non-class under the schema title.
1524- and not (
1525- isinstance (generated_cls , type )
1526- and issubclass (
1527- conflicting_cls , generated_cls
1494+ if not hasattr (model , cls_name ):
1495+ if param .autofetch_schema :
1496+ self .fetch_schema (
1497+ OSW .FetchSchemaParam (
1498+ schema_title = category ,
1499+ mode = "append" ,
1500+ offline_pages = param .offline_pages ,
1501+ )
15281502 )
1503+ if not hasattr (model , cls_name ):
1504+ schemas_fetched = False
1505+ _logger .error (
1506+ f"Model { cls_name } not found. Schema "
1507+ f"{ category } needs to be fetched first."
15291508 )
1530- ):
1531- _logger .warning (
1532- f"Class '{ generated_cls } ' generated for "
1533- f"category '{ category } ' claims the oold "
1534- f"type registry slot already held by a "
1535- f"different class '{ conflicting_cls } '."
1509+ else :
1510+ generated_cls = getattr (model , cls_name )
1511+ # The class we are about to use may have just
1512+ # claimed (or may already hold) the registry
1513+ # slot for this category. If a different class
1514+ # is registered for it, someone's registration
1515+ # was silently overwritten - do not raise, but
1516+ # make sure this does not pass silently.
1517+ conflicting_cls = oold_type_registry .get (
1518+ category
15361519 )
1537- category_to_cls [category ] = generated_cls
1520+ if (
1521+ conflicting_cls is not None
1522+ and conflicting_cls is not generated_cls
1523+ # the slot holder specializes
1524+ # generated_cls, e.g. a controller
1525+ # that inherits the category IRI:
1526+ # the case the guard above expects,
1527+ # not a conflict. A fetch can leave
1528+ # a non-class under the schema title.
1529+ and not (
1530+ isinstance (generated_cls , type )
1531+ and issubclass (
1532+ conflicting_cls , generated_cls
1533+ )
1534+ )
1535+ ):
1536+ _logger .warning (
1537+ f"Class '{ generated_cls } ' generated for "
1538+ f"category '{ category } ' claims the oold "
1539+ f"type registry slot already held by a "
1540+ f"different class '{ conflicting_cls } '."
1541+ )
1542+ category_to_cls [category ] = generated_cls
1543+ except Exception as e :
1544+ schemas_fetched = False
1545+ _logger .error (
1546+ f"Error reading the schema of category "
1547+ f"{ category } for page { page .title } : { e } "
1548+ )
1549+ continue
15381550 if not schemas_fetched :
15391551 continue
15401552 # fetch_schema() reloads osw.model.entity, which replaces every
0 commit comments