← Back to Pull requests

fix(types): read local images referenced by a Windows path #1038

Open
unknown opened this pull request with 467 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 14, 2026 14:35 UTC
Author

What

Resolves #1037

On Windows, ImageRef never reads an image whose uri is an absolute path. pydantic parses C:\x\img.png as an AnyUrl with scheme c, and _local_path() only counted Path values and file: URLs as local, so load_local_images() skipped these images without an error. docling-core writes such paths itself: save_as_json(..., image_mode=ImageRefMode.REFERENCED) with an absolute file name stores absolute image paths, and load_from_json(..., allow_local_images=True) then comes back without them.

file: URIs from Path.as_uri() had a similar problem on Windows. file:///C:/x/img.png became Path("/C:/x/img.png"), which Windows reads as \C:\x\img.png, so opening it failed with OSError: [WinError 123].

Fix

Both changes are in ImageRef._local_path(), which pil_image, load_local_images() and _with_embedded_pictures() all use to decide what's local:

  • A one-letter scheme is read as a Windows drive, the same rule _escape_uri_path and is_safe_hyperlink already use in transforms/serializer/common.py. The URL text is unquoted because pydantic percent-encodes non-ASCII characters (é becomes %C3%A9).

  • file: URL paths go through urllib.request.url2pathname instead of unquote. On Linux and macOS it unquotes the path like before. On Windows it turns /C:/x/img.png into C:\x\img.png.
  • The type of uri and the JSON output don't change, so there's no schema bump.

    One behaviour change: a drive path now counts as a local path on every OS, so it goes through the allow_image_file_uri check like any other local path. With the check off, pil_image raises the usual ValueError instead of returning None. On Linux, load_local_images() should now report a Windows absolute path as not found instead of skipping it, the same as it does for a relative Windows path there (from reading _load_local_image, I haven't run it on Linux).

    How I checked it

    Windows 11, Python 3.13.7, env from uv sync --frozen --all-extras --all-packages (I had to skip tree-sitter-java-orchard, which has no wheel and needs MSVC to build).

  • New test test_windows_drive_path_is_gated_as_local_image (C:\images\fig.png and C:/images/fig.png). It runs on Linux CI too. On main both cases fail with Failed: DID NOT RAISE ValueError.

  • The existing local-image tests already cover the rest, they just don't run on Windows in CI. pytest tests/test_docling_doc.py -k "local or file_uri" on Windows: 19 failed, 6 passed on main, 1 failed, 26 passed with the fix. The one left is test_file_uri_allowed_with_env_var, which writes to /tmp and fails the same way on main.

  • The round trip from the issue now prints image loaded: True (was False). Through docling, the JSON from docling convert --to json --image-export-mode referenced reloads with 6 of 6 embedded images (was 0 of 6).

  • Full suite on Windows: 305 failed, 1226 passed, 12 skipped, 1 xfailed on this branch vs 323 failed, 1206 passed, 12 skipped, 1 xfailed on main. The 18 that now pass are the local-image tests in test_docling_doc.py, and nothing new fails. The rest fail the same way on main (mostly the DocLang tests, plus backslash paths written on Windows, which is #837). pytest packages/dclq/tests: 10 passed.

  • make check steps (ruff format, ruff check, ty, check_compat_projectors.py, uv lock --locked) and prek run --files on the two changed files pass.
  • I didn't run anything on Linux or macOS. On those systems the file: branch does what it did before, and the new test doesn't depend on the OS.

    Related: #836 / #837 are about the separators that get written. This only changes how paths are read back, and it merges cleanly with #836.

    Diff: 467 lines (+350 / -117) across 5 files Reviewer: chrikrah Review duration: 3920m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 467 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.368
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1038"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.3% · Safe to merge
    24.3%