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

Đang mở
#483 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

@RaphaelFakhri đang làm issue này rồi.

Từ ngày 22/10/2026.

  • #484 của @RaphaelFakhri — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
504
Fork
65
Merge trung bình
6 ngày 9 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của plotly/kaleido

Tất cả issue của plotly/kaleido

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.