Commit d235ef3
committed
Fix to_binary crash on missing datacontenttype or non-string attrs
The Kafka binary conversion to_binary() read the optional datacontenttype
attribute with event["datacontenttype"], raising KeyError for any event that
does not set it (datacontenttype is optional in the CloudEvents spec). It also
called .encode() directly on attribute values, raising AttributeError for
spec-legal non-string extension attributes (e.g. integers).
Read datacontenttype via .get() -- matching the sibling to_structured(), which
already guards this attribute -- and stringify attribute values before encoding,
matching the newer core Kafka binding. Add regression tests for both cases.
Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>1 parent 24842fd commit d235ef3
2 files changed
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
96 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | | - | |
| 101 | + | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
132 | 146 | | |
133 | 147 | | |
134 | 148 | | |
| |||
0 commit comments