Skip to content

🐛 FIX: Don't crash on nested YAML dates in front matter - #1205

Open
00200200 wants to merge 1 commit into
executablebooks:masterfrom
00200200:fix/nested-frontmatter-dates
Open

00200200 wants to merge 1 commit into
executablebooks:masterfrom
00200200:fix/nested-frontmatter-dates

Conversation

@00200200

Copy link
Copy Markdown

Fixes #1203.

dict_to_fm_field_list already treats top-level YAML date/datetime scalars as displayable values, but a date one level down in a mapping or sequence reached json.dumps with no default= handler. That raises TypeError (Object of type date is not JSON serializable), which was not in the existing except (ValueError, RecursionError), so the Sphinx/docutils build aborted even with --keep-going.

This serializes nested values with default=str (same string form as a top-level date after str(value)), and treats remaining TypeErrors — e.g. a YAML date used as a mapping key — as the existing “could not be serialized” warning.

Tests

  • tests/test_docutils.py::test_topmatter_nested_dates_do_not_crash — nested date in a mapping, nested date in a sequence, nested datetime
  • tests/test_docutils.py::test_topmatter_date_mapping_key_warns — date-as-key warns instead of crashing

pytest tests/test_docutils.py — 39 passed.

…oks#1203)

json.dumps of front-matter mappings/lists raised TypeError for nested
date/datetime values. Stringify those with default=str, and catch TypeError
so a YAML date used as a mapping key warns instead of aborting the build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Front matter: a date nested in a dict or list crashes the build (TypeError in dict_to_fm_field_list)

1 participant