Keep the market-hours database when a refresh returns malformed JSON
维护者通常 2 天内回复
评估
调研方向
Read lean/components/cloud/data_downloader.py and lean/components/util/market_hours_database.py to trace the download, file replacement, refresh timestamp, and JSON reader behavior. Check the existing tests for these components, then add the described regression case with a valid cached database and malformed response. Done means invalid content leaves the prior database usable and refresh is recorded only after a successful update. An open linked pull request (#710) is already against this issue.
由索引模型根据 Issue 内容生成。
描述
Problem
On master (d812d26), a successful HTTP response containing malformed JSON can overwrite a usable local market-hours database. Subsequent database reads fail instead of retaining the last valid data.
The path is:
DataDownloader.update_database_files()(lean/components/cloud/data_downloader.py:83-92) downloads the market-hours database and passes its bytes directly to_store_local_file.DataClient.download_public_file()(lean/components/api/data_client.py:89-95) returns raw response content, without JSON validation._store_local_file()(lean/components/cloud/data_downloader.py:24-27) opens the existing file withwb+and writes those bytes.MarketHoursDatabase._get_all_entries()(lean/components/util/market_hours_database.py:63-69) only parses the JSON when it is later read.
The refresh timestamp is also recorded before the download/write (data_downloader.py:85), so a malformed successful response can leave the bad file in place until the next configured refresh interval.
Synthetic reproduction
With the CLI installed and initialized, this uses only a temporary file, not an actual data directory:
import json
import tempfile
from pathlib import Path
from lean.components.cloud.data_downloader import _store_local_file
with tempfile.TemporaryDirectory() as directory:
cache = Path(directory) / "market-hours-database.json"
previous = '{"entries": {}}'
cache.write_text(previous, encoding="utf-8")
# Bytes returned by a malformed HTTP 200 response.
_store_local_file(b"not json", cache)
print(cache.read_text(encoding="utf-8")) # not json; valid data is lost
json.loads(cache.read_text(encoding="utf-8")) # JSONDecodeError
I verified the same result using the isolated _store_local_file function from master: the file becomes not json, and the next decode raises JSONDecodeError. This is a synthetic malformed response, not a report that the hosted database is currently malformed.
Suggested fix
Validate the downloaded market-hours content using the format accepted by its reader (including supported comments and the required entries structure) before replacing the local file. Write through a temporary file, preserve the existing file's access metadata, and replace only after validation and writing succeed. Record a successful refresh only after it completes. Add a regression test with a pre-existing valid database and a malformed successful response.
- 主要语言
- Python
- 星标
- 330
- 派生
- 171
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 18
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
QuantConnect/lean-cli 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 50/100
QuantConnect/lean-cli#706 ·
维护者通常 2 天内回复
-
OAuth: non-interactive deployment discards a valid saved account when multiple accounts are authorized可能已有人在做 @pcbeingused333 今天认领。 未关闭
难度 3/5 半天 新手友好度 62/100
QuantConnect/lean-cli#699 ·
维护者通常 2 天内回复
-
cloud pull --encrypt leaves the project without its key path and encrypts referenced libraries可能已有人在做 @Amadeus-22 于 6 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 25/100
QuantConnect/lean-cli#688 ·
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
QuantConnect/lean-cli#681 ·
维护者通常 2 天内回复
-
难度 5/5 一周以上 新手友好度 25/100
QuantConnect/lean-cli#619 ·
维护者通常 2 天内回复
查看 QuantConnect/lean-cli 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
FinanceFlash/unvibecode#509 ·
-
难度 1/5 1 小时以内 新手友好度 82/100
FAIRmat-NFDI/nomad-distro-dev#161 ·
-
bug v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/python-sdk#3821 · 1 条评论 ·
维护者通常 1 天内回复
-
bug severity:low
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
Log-odds calibration uses upper middle score instead of median for even candidate sets可能已有人在做 @flysheep-ai 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复