fix(critical): resolve three critical runtime bugs in MetadataFigure - #64
Merged
Conversation
1. has_caption NameError: initialise has_caption and caption_child before the inner loop so the variables are always defined even when node.children is empty, and stop relying on loop-variable leakage for the caption_child reference used after the loop. 2. License URL lookup broken in non-English locales: preserve the English (pre-translation) license key in figure_node["license_key"] and use it exclusively for LICENSE_URLS lookups in _build_attribution_display, so licence hyperlinks are generated correctly regardless of the active Sphinx locale. 3. ValueError in _copyright_from_authoryear: wrap both strptime calls in try/except ValueError so that a BibTeX date that is not in YYYY-MM-DD format (e.g. a bare year from the year= field) does not crash the build; the year is simply omitted from the copyright string instead. https://claude.ai/code/session_01ApsmWPWsKBesMV1rq2VenA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three critical bugs that can crash the build or silently produce wrong output.
1.
has_caption—NameErrorwhen a figure node has no children (__init__.py:779)has_caption = Falsewas initialised inside the innerfor child in node.children:loop body, so it was reset on every iteration and left undefined whennode.childrenis empty. The subsequentif has_caption:then raisesNameError. Additionally, the caption node reference (child) after the loop relied on silent loop-variable leakage — fragile and hard to read.Fix: initialise
has_caption = Falseandcaption_child = Nonebefore the inner loop; capture the caption node incaption_childand use that variable after the loop.2. License URL links broken in non-English locales (
__init__.py:608, 812, 937)figure_node["license"]stored the translated display value (e.g. German), butLICENSE_URLSis keyed by English names only. Thein LICENSE_URLSlook-up therefore always failed for non-English builds, so no license hyperlink was ever generated.Fix: save the English (pre-translation) key in
license_key_enimmediately afteruntranslate_license()and store it asfigure_node["license_key"]._build_attribution_displaynow usesfigure_node.get("license_key", figure_node["license"])for the URL look-up.3.
ValueErrorcrash in_copyright_from_authoryear(__init__.py:892, 897)Both
datetime.strptime(date_value, "%Y-%m-%d")calls had no exception handling. A date that arrives from a BibTeXyear =field (e.g."2023"or a partial date) and bypasses the directive-level validation crashes the build with an unhandledValueError.Fix: wrap both
strptimecalls intry/except ValueError; when the date cannot be parsed the year is simply omitted from the copyright string rather than raising.Test plan
language = "de") and confirm license hyperlinks appear in the output HTML.NameError.year = {2023}(no month/day) and use it via:bib:; confirm the build completes and copyright is shown without a year.https://claude.ai/code/session_01ApsmWPWsKBesMV1rq2VenA