Skip to content

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

Description

@PiotrRozenfeld

What version of myst-parser are you using?

5.1.0

What version dependencies are you using?

Sphinx 8.2.3, docutils 0.21.2, Python 3.12

What operating system are you using?

Windows

Describe the Bug

A YAML date nested inside a dict or a list in the front matter stops the whole Sphinx build:

File "myst_parser/mdit_to_docutils/base.py", line 1390, in dict_to_fm_field_list
  value = json.dumps(value)
TypeError: Object of type date is not JSON serializable

dict_to_fm_field_list lets top-level date / datetime values through the isinstance check
(this was the fix for #252), but a date one level down reaches json.dumps(value) with no
default=. The except (ValueError, RecursionError) around that call does not catch TypeError,
so this is an exception, not a warning, and --keep-going does not help.

Expected Behavior

The build succeeds. Either of these one-line changes fits the existing code:

  • json.dumps(value, default=str) - the nested date becomes an ISO string, the same as a
    top-level date after str(value).
  • Add TypeError to the existing except (ValueError, RecursionError), so the field is skipped
    with the same MD_TOPMATTER warning.

I tested the first one on master (Linux and Windows): all four cases below then build with no
warnings.

To Reproduce

conf.py:

extensions = ["myst_parser"]

index.md:

---
review:
  date: 2026-08-03
---
# Test

Run sphinx-build -b html . _build. The build stops with the TypeError above.

Results for four variants (same result on 5.1.0 and on master, on Linux and on Windows):

Front matter Result
last_updated: 2026-08-03 (top level) builds
review: {date: 2026-08-03} (nested in a dict) TypeError
reviewed: [2026-08-03] (nested in a list) TypeError
review: {date: "2026-08-03"} (nested, quoted) builds

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions