Kafka `to_binary()` crashes on events without `datacontenttype` or with non-string attributes
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- kafka, python
- Ambito
- distributed-systems
Direzione di ricerca
Inizia in cloudevents/v1/kafka/conversion.py e confronta to_structured() con il binding Kafka core più recente menzionato nell’issue. Verifica che entrambe le riproduzioni vengano completate senza eccezioni, che content-type venga omesso quando datacontenttype è assente e che gli attributi di estensione non stringa vengano convertiti in stringhe negli header generati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
to_binary() in cloudevents/v1/kafka/conversion.py raises on two kinds of perfectly valid CloudEvents:
1. Missing datacontenttype (optional attribute) → KeyError
headers = {}
if event["datacontenttype"]: # KeyError if unset
headers["content-type"] = event["datacontenttype"].encode("utf-8")
datacontenttype is optional, so event["datacontenttype"] raises KeyError for any event that does not set it. The sibling to_structured() in the same file already guards this with if "datacontenttype" in attrs:.
2. Non-string attribute value → AttributeError
if value is not None:
headers["ce_{0}".format(attr)] = value.encode("utf-8") # AttributeError if not str
CloudEvents extension attributes may be non-string (e.g. Integer/Boolean), so value.encode(...) raises AttributeError: 'int' object has no attribute 'encode'. The newer core Kafka binding already does str(attr_value).encode(...).
Reproduction
from cloudevents.v1.http import CloudEvent
from cloudevents.v1.kafka import to_binary
# 1) no datacontenttype -> KeyError: 'datacontenttype'
to_binary(CloudEvent({"type": "t", "source": "s"}, {"a": 1}))
# 2) non-string extension -> AttributeError: 'int' object has no attribute 'encode'
to_binary(CloudEvent({"type": "t", "source": "s",
"datacontenttype": "application/json", "ext1": 5}, {"a": 1}))
Expected behaviour
to_binary() should handle both valid events: omit the content-type header when datacontenttype is absent, and stringify non-string attribute values.
- 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
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cloudevents/sdk-python#300 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cloudevents/sdk-python#291 · 8 commenti ·
-
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 🔔 Pending processing
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
OpenHands/extensions#626 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
CSCfi/sd-search-api#39 ·