Skip to content

Commit 9e134e0

Browse files
committed
feat: Allow falling back to internal rendering on any cache error
Previously, passing `fallback_render_aird` would only cause a fallback to the internal rendering engine on cache misses. With this commit, diagrams are also rendered internally for any other cache error, for example if a remote cache server is unreachable or the cached artifacts have expired.
1 parent 7ecc83c commit 9e134e0

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

src/capellambse/model/_model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,14 @@ def __init__(
254254
255255
*This argument is **not** passed to the file handler.*
256256
fallback_render_aird: bool
257-
If set to True, enable the internal engine to render
258-
diagrams that were not found in the pre-rendered cache.
259-
Defaults to False, which means an exception is raised
260-
instead. Ignored if no ``diagram_cache`` was specified.
257+
If set to True, always fall back to rendering diagrams
258+
internally if the configured ``diagram_cache`` is not
259+
available.
260+
261+
By default, the internal renderer is entirely disabled for
262+
AIRD diagrams, and only used during cache misses
263+
(``FileNotFoundError`` from the underlying file handler) for
264+
all other types of diagrams.
261265
**kwargs
262266
Additional arguments are passed on to the underlying
263267
:class:`~capellambse.loader.core.MelodyLoader`, which in

src/capellambse/model/diagram.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,14 @@ def _allow_render(self) -> bool: ...
223223

224224
else:
225225
_allow_render: bool = True
226-
"""Allow this diagram to be rendered by the internal rendering engine.
226+
"""Always allow rendering this diagram with the internal engine.
227227
228228
If this property is set to False, and a diagram cache was
229229
specified for the model, this diagram can only be loaded from
230-
the cache, and will never be rendered. Has no effect if there
231-
was no diagram cache specified.
230+
the cache, and will never be rendered. If set to True, a cache
231+
miss will instead cause the diagram to be rendered internally.
232+
233+
Has no effect if there was no diagram cache specified.
232234
233235
:meta public:
234236
"""
@@ -400,10 +402,25 @@ def render(
400402
try:
401403
return self.__load_cache(chain)
402404
except KeyError:
403-
pass
404-
405-
if not self._allow_render:
406-
raise RuntimeError(f"Diagram not in cache: {self.name}")
405+
if not (
406+
self._model._fallback_render_aird or self._allow_render
407+
):
408+
raise RuntimeError(
409+
f"Diagram not in cache: {self.name}"
410+
) from None
411+
except Exception:
412+
if not self._model._fallback_render_aird:
413+
raise
414+
LOGGER.warning(
415+
(
416+
"Diagram cache lookup failed,"
417+
" falling back to internal renderer"
418+
" for diagram %r (%s)"
419+
),
420+
self.name,
421+
self.uuid,
422+
exc_info=True,
423+
)
407424

408425
render = self.__render_fresh(params)
409426
return _run_converter_chain(chain, render, pretty_print=pretty_print)
@@ -634,9 +651,10 @@ class DRepresentationDescriptor(AbstractDiagram):
634651
description = _pods.HTMLStringPOD("documentation")
635652

636653
_element: aird.DRepresentationDescriptor
637-
638654
_node_cache: list[etree._Element]
639655

656+
_allow_render = False
657+
640658
@classmethod
641659
def from_model(
642660
cls,
@@ -700,10 +718,6 @@ def semantic_nodes(self) -> _obj.ElementList:
700718
elems.append(obj._element)
701719
return _obj.ElementList(self._model, elems, legacy_by_type=True)
702720

703-
@property
704-
def _allow_render(self) -> bool:
705-
return self._model._fallback_render_aird
706-
707721
@property
708722
def viewpoint(self) -> str:
709723
return aird.viewpoint_of(self._element)

0 commit comments

Comments
 (0)