Skip to content

fix(types): close local image files read by ImageRef.pil_image - #1097

Open
Yogeshwar-CM wants to merge 1 commit into
docling-project:mainfrom
Yogeshwar-CM:fix/close-local-image-file
Open

Yogeshwar-CM wants to merge 1 commit into
docling-project:mainfrom
Yogeshwar-CM:fix/close-local-image-file

Conversation

@Yogeshwar-CM

Copy link
Copy Markdown

Fixes #1096

Summary

ImageRef.pil_image kept the PILImage.open(local_path) result, so a local image file stayed open until Pillow loaded the pixels, or for the life of the image for multi-frame files. It now reads the image the same way _load_local_image already does: open it in a with block and keep a copy, so the file is closed before pil_image returns.

The data: URI branch is unchanged, because it reads from an in-memory BytesIO.

Tests

  • New test_file_uri_image_does_not_keep_file_open: reads a file:// image, drops the references, and asserts no ResourceWarning. It fails without the change and passes with it.
  • test_file_uri_allowed_with_env_var now also passes under pytest -W error.
  • Full suite: 1915 passed. The only failure under -W error is an unrelated socket ResourceWarning in test_visualization.py::test_doc_visualization, which also fails on main.
  • ruff check and ruff format --check pass on the changed files.

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @Yogeshwar-CM, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added bug Something isn't working document-model DoclingDocument core model, metadata, hierarchy, validation labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 4c47b54aeb. The analysis read the diff only. It did not run code from this pull request.

Warning

The AI analysis did not finish. Only the deterministic checks are shown.

CI safety: not assessed.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

Fixes docling-project#1096

Signed-off-by: Yogeshwar CM <84910252+Yogeshwar-CM@users.noreply.github.com>
@Yogeshwar-CM
Yogeshwar-CM force-pushed the fix/close-local-image-file branch from e6420f5 to 4c47b54 Compare November 28, 2026 14:22

This branch has not been deployed

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

Labels

bug Something isn't working document-model DoclingDocument core model, metadata, hierarchy, validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageRef.pil_image leaves local image files open

1 participant