Skip to content

Handling of null ctx in AvroDeserializer #1973

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

Closed
and-ratajski opened this issue Apr 18, 2025 · 0 comments · Fixed by #1974
Closed

Handling of null ctx in AvroDeserializer #1973

and-ratajski opened this issue Apr 18, 2025 · 0 comments · Fixed by #1974

Comments

@and-ratajski
Copy link
Contributor

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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants