Skip to content

Handling of null ctx in AvroDeserializer #1973

@and-ratajski

Description

@and-ratajski

Similar issue reported in #1939 but for AvroDeserializer...

So when avro deserializer is called without (optional) parameter named ctx following Attribute Error is raised:

AttributeError: 'NoneType' object has no attribute 'topic'

in here:

    def topic_subject_name_strategy(ctx, record_name: Optional[str]) -> Optional[str]:
        """
        Constructs a subject name in the form of {topic}-key|value.
    
        Args:
            ctx (SerializationContext): Metadata pertaining to the serialization
                operation.
    
            record_name (Optional[str]): Record name.
    
        """
>       return ctx.topic + "-" + ctx.field
E       AttributeError: 'NoneType' object has no attribute 'topic'

Steps to reproduce:

schema_registry_client = SchemaRegistryClient(...)
local_schema = '''
{
  "type": "record",
  "name": "FooRecord",
  "namespace": "com.confluent_kafka.issue",
  "fields": [
    {
      "name": "foo",
      "type": ["string"]
    }
  ]
}
'''

deserializer = AvroDeserializer(schema_registry_client, local_schema)
msg = deserializer(b'\x00\x00\x00\x10\x00\bar')

Metadata

Metadata

Assignees

No one assigned

    Labels

    component:schema-registryAny schema registry related isues rather than kafka isolated ones

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions