Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3118

Namespace with empty string is not treated as null in Python API

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.10.2
    • Fix Version/s: 1.11.0
    • Component/s: python
    • Labels:
      None

      Description

      Hi,

      based on the AVRO documentation an empty string may also be used as a namespace to indicate the null namespace.

      The Python package doesn't do that. Following example will fail when parsing:

      import avro.schema
      schema_str="""
      {"type": "record", "name": "my_schema", "namespace": "my_ns",
       "fields": [{"name": "field_a", "type": {"type": "record", "name": "row", "namespace": "",
       "fields": [{"name": "subfield", "type": "string"}]}},
       {"name": "field_b", "type": "row"}
       ]}
      """
      schema = avro.schema.parse(schema_str)
      

      Raised exception is "SchemaParseException: Type property "row" not a valid Avro schema: Could not make an Avro Schema object from row."

      If I set the namespace in the in the subfield to null it's working.

      Problem for me is, that I can't change the schema definition. The schema is in the Kafka schema repository. The Kafka AVRO consumer receives this from the schema registry server with an empty string.

      I could fix this by adding a check in the parser source schema.py:

       

      ...
      return writer.type == self.type and (self.type == 'request' or self.check_props(writer, ['fullname']))
      def __init__(self, name, namespace, fields, names=None, schema_type='record', doc=None, other_props=None):
          # Fixing empty namespace
          if namespace == '':
              namespace = None
       
          # Ensure valid ctor args
          if fields is None:
              ...
      

       

       

        Attachments

          Activity

            People

            • Assignee:
              kojiromike Michael A. Smith
              Reporter:
              dega Frank Mieves
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: