Skip to content

FIX Include the output settings in the ImageCompressionConverter identifier - #3365

Merged
Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
feiiiiii5:fix/image-compression-identifier
Oct 20, 2026
Merged

Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
feiiiiii5:fix/image-compression-identifier

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Description

Follow-up to #3245, which fixed the same identifier gap for QRCodeConverter and PDFConverter and named ImageCompressionConverter as the remaining case.

ImageCompressionConverter._build_identifier() includes the output format, quality, compress level, lossless and method, but omits three settings that change the produced image or the conversion outcome:

  • background_color fills transparent pixels when the output mode has no alpha channel.
  • min_compression_threshold decides whether a smaller compressed candidate is kept.
  • fallback_to_original decides whether an unsuccessful compression returns the original bytes.

Two converters that differ only in these settings therefore share get_identifier().hash and the default registry name. Registering the second one raises ValueError: Instance 'ImageCompressionConverter::...' already exists, and a lookup by that name returns the wrong instance. The three settings are now part of the identifier params. Defaults are unchanged, so the default hash stays the same.

Tests and Documentation

Added tests in tests/unit/converter/test_image_compression_converter.py:

  • each of the three settings changes the hash and lets both instances register;
  • the three settings appear in the identifier params;
  • equal settings keep the same hash (including both defaults).

Local runs (PYTHONPATH=. python -m pytest -p no:opik -p no:ddtrace):

  • tests/unit/converter/test_image_compression_converter.py: 32 passed.
  • On main (71a01b3), the three distinction cases and the identifier-params test fail because the hashes collide; the equal-settings test passes. With this change all four pass.
  • ruff check and ruff format --check pass on both changed files.

No documentation pages change, so no JupyText run was needed.

@romanlutz Roman Lutz (romanlutz) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! I will make a tiny change and otherwise it's ready to merge.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>\nCopilot-Session: 11737ed7-7291-4e15-b8d5-b379f3a64ac4
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 11737ed7-7291-4e15-b8d5-b379f3a64ac4
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 20, 2026
Merged via the queue into microsoft:main with commit b249183 Oct 20, 2026
98 of 99 checks passed
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.

2 participants