`JSONFormat` shouldn't depend on Content-Type to avoid generating invalid JSON
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
Direzione di ricerca
Inizia in src/cloudevents/core/formats/json.py alla riga indicata e analizza la gestione di data e Content-Type da parte di JSONFormatter. Verifica che i dati di tipo dizionario producano JSON valido anche con application/octet-stream, ed esegui i test pertinenti del formatter oppure aggiungi la relativa copertura per questo caso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi,
i just upgraded my service to v2.
The problem:
- the service which produces the cloudevents is maintained by another team, i.e. not in my control
- they send the events with Content-Type
application/octet-stream - therefore, in my tests i also emulate sending the events with that Content-Type:
event = CloudEvent(
attributes={..., "datacontenttype": "application/octet-stream"},
data=payload, # <- this is a dictionary
)
message = tobinary_event(event)
client.post("/trigger", content=message.body, headers=message.headers)
now my tests started to send invalid json data (using single quotes instead of double quotes). The reason is this line. E.g. it converts {"asdf": True} to b"{'asdf', True}".
i initially didn't realise this comes from my test case and assumed the SDK generates the invalid data. It took me a while to figure out that only my test setup is wrong.
Proposed solution:
I think str(data).encode("utf-8") is a bad default. Instead, the JSONFormatter should always try to return dumps(data, cls=_JSONEncoderWithDatetime).encode("utf-8"), regardless of the content type. it's the JSONFormatter, so when i pass in a dictionary, i expect it to generate valid json. If it can't, then it's fine to fail with a json.JSONDecodeError or the like. Imo, failing is better than silently generating invalid request data.
Wdyt?
- Lingua principale
- Python
- Stelle
- 342
- Fork
- 65
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
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 cloudevents/sdk-python
-
Kafka `to_binary()` crashes on events without `datacontenttype` or with non-string attributes Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cloudevents/sdk-python#304 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cloudevents/sdk-python#300 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 48/100
cloudevents/sdk-python#247 · 2 commenti ·
-
question
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
cloudevents/sdk-python#246 · 5 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
cloudevents/sdk-python#213 · 3 commenti · 1 reazione ·
Tutte le issue di cloudevents/sdk-python
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
huggingface/Repo2RLEnv#163 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
NousResearch/hermes-agent#121143 ·