fix(types): read local images referenced by a Windows path #1038
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
chrikrah
What
Resolves #1037
On Windows,
ImageRefnever reads an image whoseuriis an absolute path. pydantic parsesC:\x\img.pngas anAnyUrlwith schemec, and_local_path()only countedPathvalues andfile:URLs as local, soload_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, andload_from_json(..., allow_local_images=True)then comes back without them.file:URIs fromPath.as_uri()had a similar problem on Windows.file:///C:/x/img.pngbecamePath("/C:/x/img.png"), which Windows reads as\C:\x\img.png, so opening it failed withOSError: [WinError 123].Fix
Both changes are in
ImageRef._local_path(), whichpil_image,load_local_images()and_with_embedded_pictures()all use to decide what's local:_escape_uri_pathandis_safe_hyperlinkalready use intransforms/serializer/common.py. The URL text is unquoted because pydantic percent-encodes non-ASCII characters (ébecomes%C3%A9).file:URL paths go throughurllib.request.url2pathnameinstead ofunquote. On Linux and macOS it unquotes the path like before. On Windows it turns/C:/x/img.pngintoC:\x\img.png.The type of
uriand 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_uricheck like any other local path. With the check off,pil_imageraises the usualValueErrorinstead of returningNone. 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 skiptree-sitter-java-orchard, which has no wheel and needs MSVC to build).test_windows_drive_path_is_gated_as_local_image(C:\images\fig.pngandC:/images/fig.png). It runs on Linux CI too. Onmainboth cases fail withFailed: DID NOT RAISE ValueError.pytest tests/test_docling_doc.py -k "local or file_uri"on Windows:19 failed, 6 passedonmain,1 failed, 26 passedwith the fix. The one left istest_file_uri_allowed_with_env_var, which writes to/tmpand fails the same way onmain.image loaded: True(wasFalse). Through docling, the JSON fromdocling convert --to json --image-export-mode referencedreloads with6 of 6embedded images (was0 of 6).305 failed, 1226 passed, 12 skipped, 1 xfailedon this branch vs323 failed, 1206 passed, 12 skipped, 1 xfailedonmain. The 18 that now pass are the local-image tests intest_docling_doc.py, and nothing new fails. The rest fail the same way onmain(mostly the DocLang tests, plus backslash paths written on Windows, which is #837).pytest packages/dclq/tests:10 passed.make checksteps (ruff format, ruff check, ty,check_compat_projectors.py,uv lock --locked) andprek run --fileson 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.