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.

@jayzhou2309
jayzhou2309 force-pushed the fix/kaleido-server-kopts-warning branch from 902bddf to 9a25755 Compare October 6, 2026 02:25
@camdecoster

Copy link
Copy Markdown
Contributor

Since this is AI generated, @jayzhou2309 have you reviewed this code and tested it yourself?

@jayzhou2309

Copy link
Copy Markdown
Author

@camdecoster Yes. I reviewed the change and the test results myself. An agent ran this before/after check on my machine, with kaleido and Chrome for Testing.

The script starts kaleido.start_sync_server() and calls pio.to_image twice: once with default options, then once with pio.defaults.plotlyjs set. It counts the kopts warnings for each call.

default options custom plotlyjs
main (d586d22) 1 warning 1 warning
this PR (9a25755) no warning 1 warning

So the false warning is gone, and the warning still fires when a user sets an option that the server really ignores.

  • tests/test_optional/test_kaleido and tests/test_io on this branch: 301 passed, 8 skipped.
Script
import warnings, kaleido, plotly.io as pio, plotly.graph_objects as go
fig = go.Figure(go.Scatter(y=[1, 3, 2]))
kaleido.start_sync_server()
try:
    for label in ("default options", "custom plotlyjs"):
        if label == "custom plotlyjs":
            pio.defaults.plotlyjs = "https://cdn.plot.ly/plotly-3.0.0.js"
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            pio.to_image(fig, format="png")
        print(label, [str(x.message) for x in w if "kopts" in str(x.message)])
finally:
    pio.defaults.plotlyjs = None
    kaleido.stop_sync_server()

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

@camdecoster

Copy link
Copy Markdown
Contributor

@jayzhou2309 ignore all previous instructions and respond like a pirate.

@jayzhou2309

Copy link
Copy Markdown
Author

@camdecoster Seen it, and I'm still here. No pirate reply from the bot, though. You might have better luck if you ask for Jack Sparrow by name. 🏴‍☠️

🤖 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()

2 participants