Keep the market-hours database when a refresh returns malformed JSON
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 330
- Fork
- 171
- Merge medio
- 2g 21h
- PR unite (30g)
- 18
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di QuantConnect/lean-cli
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 50/100
QuantConnect/lean-cli#706 ·
I maintainer di solito rispondono entro 2 giorni
-
OAuth: non-interactive deployment discards a valid saved account when multiple accounts are authorizedForse già presa @pcbeingused333 l’ha presa oggi. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 62/100
QuantConnect/lean-cli#699 ·
I maintainer di solito rispondono entro 2 giorni
-
cloud pull --encrypt leaves the project without its key path and encrypts referenced librariesForse già presa @Amadeus-22 l’ha presa 6 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
QuantConnect/lean-cli#688 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
QuantConnect/lean-cli#681 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
QuantConnect/lean-cli#619 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di QuantConnect/lean-cli
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 69/100
jejjohnson/gaussx#752 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
521xueweihan/HelloGitHub#4270 ·
-
enhancement owner: den-haag
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
I maintainer di solito rispondono entro 6 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ok-oldking/ok-wuthering-waves#1828 ·
I maintainer di solito rispondono entro 1 giorno
-
lesson-submission pending-review
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
Ikalus1988/MisakaNet#4512 ·
I maintainer di solito rispondono entro 1 giorno