Skip to content

Don't warn about default kopts under a kaleido sync server - #5787

Open
jayzhou2309 wants to merge 2 commits into
plotly:mainfrom
jayzhou2309:fix/kaleido-server-kopts-warning
Open

jayzhou2309 wants to merge 2 commits into
plotly:mainfrom
jayzhou2309:fix/kaleido-server-kopts-warning

Conversation

@jayzhou2309

Copy link
Copy Markdown

Link to issue

Closes #5786

Description of change

plotly.io.defaults.headers is always set (X-Requested-With: plotly.py, for the Open Street Map tile policy), so every export passes a non-empty kopts to kaleido. Under kaleido.start_sync_server(), kaleido ignores kopts and warns whenever it is truthy. So write_image, to_image and write_images warned on every call, even when the user set no Kaleido options.

This PR ignores that one warning only when kopts holds nothing but plotly's default headers. If defaults.plotlyjs, defaults.mathjax or custom defaults.headers are set, the warning still fires, since those options really are dropped by the server. The default header moves to a DEFAULT_HEADERS constant in plotly/io/_defaults.py so the check can compare against it. _sg_scraper.py already filters the same warning around its exports. It is unchanged here, because it passes user options to its own server.

Kaleido has no public way to ask whether the sync server is running, so the other route (skip kopts when a server runs) would need its private _global_server.

Demo

The script from the issue, with kaleido 1.3.0 and Chrome for Testing:

  • main (d586d22): ['The kopts argument is ignored if using a server.', 'The kopts argument is ignored if using a server.'] for one write_image and one to_image
  • this PR: []

Testing strategy

  • test_sync_server_no_kopts_warning_for_default_options starts a real kaleido sync server and runs to_image, write_image and write_images with default options. It fails on main (3 warnings) and passes here.
  • test_sync_server_warns_when_options_are_ignored sets defaults.plotlyjs and checks the warning still fires. It passes on main and here.
  • tests/test_optional/test_kaleido and tests/test_io: 301 passed, 8 skipped.
  • ruff format --check passes on the changed files. ruff check reports only the unused import os in _kaleido.py, which is already on main.

AI disclosure

An AI agent (Claude Code) reproduced the issue, wrote the failing tests and the fix, and ran the commands above.

Guidelines


🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Unnecessary UserWarning when using fig.write_image() with kaleido.start_sync_server()

1 participant