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

未关闭
#483 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@RaphaelFakhri 已经在做这个了。

开始于 2026年10月22日。

  • #484 来自 @RaphaelFakhri —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

Read coerce_for_js and determine_path, along with the existing test_determine_path_directory_with_suffix test. Reproduce the failure with an existing directory whose name contains dots, then check that the result writes Sales.png inside it and that a directory named plots.svg keeps the default PNG format. An open pull request already addresses this issue.

由索引模型根据 Issue 内容生成。

描述

bug P3 size: 1

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.

主要语言
Python
星标
504
派生
65
平均合并
6 天 9 小时
30 天内合并 PR
2

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

plotly/kaleido 的其他 Issue

查看 plotly/kaleido 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。