Skip to content

Message.__len__ fails if the value has been deserialized to a type that does not support __len__ #1192

Open
@choogeboom

Description

@choogeboom

Description

In the Message.__len__ method it gets the length of the value and returns that. Unfortunately, this means that if a user is using a DeserializingConsumer that deserializes the value to a type that does not implement __len__, then calling len(message) fails with the following error:

TypeError: object of type 'SomeTypeWithoutLen' has no len()

This causes errors if you try to use a message in a truthy manner, such as

if message:
    do_something()

or

actual_message = message or some_other_value

How to reproduce

  1. Create a topic
  2. Produce a message on the topic where the value is serialized using some avro schema
  3. Create a DeserializingConsumer with a value.deserializer that deserializes the message to a type that doesn't implement __len__, such as a dataclass representing the avro record. This can be accomplished with the from_dict attribute of the AvroDeserializer.
  4. Consume the message message = consumer.poll()
  5. Call len(message)

Checklist

Please provide the following information:

confluent-kafka-python: ('1.7.0', 17235968)
librdkafka: ('1.7.0', 17235968)

Metadata

Metadata

Assignees

Labels

bugReporting an unexpected or problematic behavior of the codebasecode:CIssues that are specific to C behavior or domain within the library independent of library logicsize:smallMaintainer triage tag for indicating change required is particularly smallstatus:help-wantedIssues that would especially appreciate external development or attention

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy