Writing to an existing directory whose name has a dot fails with "Invalid format"
评估
调研方向
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 内容生成。
描述
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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
plotly/kaleido 的其他 Issue
-
Deterministic Rendering Challenges可能重新可做 @camdecoster 于 68 天前认领,目前没有进行中的 PR。 未关闭enhancement feature P2 size: 5
-
[FEATURE]: Embed custom fonts into vector exports (no system install)可能已有人在做 @camdecoster 于 124 天前认领。 未关闭enhancement P3 size: 3
-
enhancement feature P3 size: 5
难度 5/5 一周以上 新手友好度 25/100
-
GlobalKaleidoServer is not thread-safe可能已有人在做 @talleibman 于 250 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
-
[BUG]: to_image gets stuck very rarely可能已有人在做 @AndrushaUt 于 217 天前认领。 未关闭bug
难度 4/5 3-5 天 新手友好度 48/100
相似的 Issue
-
Server mode OAuth2: 'NoneType' object is not subscriptable on every request after re-submitting the OAuth2 login while already logged in可能已有人在做 @Rarasinhoo 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
pgadmin-org/pgadmin4#10733 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
aws-samples/sample-per-model-bedrock#752 ·
维护者通常 1 天内回复
-
lesson-submission pending-review
难度 1/5 1 小时以内 新手友好度 72/100
Ikalus1988/MisakaNet#4452 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
OCHA-DAP/topo-tools#250 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复