Skip to content

Writing to an existing directory whose name has a dot fails with "Invalid format" #483

Open

Description

@RaphaelFakhri

write_fig accepts a directory as path and generates a filename from the figure title. When the directory name contains a dot, for example a date-named folder like reports/2024.01.31, the render fails with ValueError: Invalid format '31' and no file is written.

coerce_for_js reads the image format from path.suffix without checking whether path is a directory. determine_path already treats an existing directory with a suffix-like name as a directory (see test_determine_path_directory_with_suffix), so the two functions disagree.

With the default cancel_on_error=False, the error is returned in the result tuple rather than raised, so the call looks like it succeeds and the directory stays empty.

A directory named like a format, such as plots.svg, silently switches the output format to SVG instead of the default PNG.

Steps to reproduce

import pathlib
import tempfile

import kaleido

d = pathlib.Path(tempfile.mkdtemp()) / "2024.01.31"
d.mkdir()
fig = {"data": [{"type": "bar", "x": ["a", "b"], "y": [1, 2]}], "layout": {"title": {"text": "Sales"}}}

print(kaleido.write_fig_sync(fig, path=d))
print(list(d.iterdir()))

Actual result

(ValueError("Invalid format '31'.\nSupported formats: ('png', 'jpg', 'jpeg', 'webp', 'svg', 'json', 'pdf')"),)
[]

Expected result

The image is written as 2024.01.31/Sales.png, the same as for a directory without a dot.

Environment

kaleido main (a517ccc, v1.5.0), Python 3.12, Linux.

Activity

  1. camdecoster commented on Oct 26, 2026

    @camdecoster
    Contributor

    Thanks for the bug report! I'll review the PR and follow up there.

  2. added
    bug
    P3
    on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3bugsize: 1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions