Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudevents.kafka.conversion.from_structured incorrectly handles headers tuple #210

Closed
bipthelin opened this issue Feb 1, 2023 · 2 comments
Labels
wontfix This will not be worked on

Comments

@bipthelin
Copy link

Expected Behavior

from_structured/1 on a KafkaMessage i.e. ConsumerRecord in aiokafka correctly deserialize the event into a CloudEvent.

Actual Behavior

Crash:

File "/usr/local/lib/python3.11/site-packages/cloudevents/kafka/conversion.py", line 257, in from_structured
 for header, val in message.headers.items():
                    │       └ ()
                    └ ConsumerRecord(topic='topic', partition=0, offset=4, key=None, value=b'{"s..."} headers=())

AttributeError: 'tuple' object has no attribute 'items'

Steps to Reproduce the Problem

consumer = AIOKafkaConsumer(...)
consumer.start()

for msg in consumer:
    event = from_structured(msg)
... # CRASH ↑

There seems to be a discrepancy between:

Specifications

  • Platform: MacOS
  • Python Version: 3.11
  • Kafka 3.3.2
  • aiokafka: v0.8.0
@bipthelin
Copy link
Author

Reading the code it seems that I was naive in thinking that from_structured would deserialize directly from an AIOKafka ConsumerRecord. But instead I need to do something like this:

kafka_msg = KafkaMessage(headers=dict(msg.headers), key=msg.key, value=msg.value)
event = from_structured(kafka_msg)

this works as expected. Closing issue.

@xSAVIKx
Copy link
Member

xSAVIKx commented Feb 2, 2023

Thx for raising and resolving the issue 😄

Yes, the connector is generic and does not provide support for a specific library. This is intentional behavior. We may wanna add extras that provide library-specific API like we did with Pydantic.

@xSAVIKx xSAVIKx added the wontfix This will not be worked on label Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants