You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Michael A. Smith (Jira)" <ji...@apache.org> on 2021/05/14 12:57:00 UTC
[jira] [Updated] (AVRO-3118) Namespace with empty string is not
treated as null in Python API
[ https://issues.apache.org/jira/browse/AVRO-3118?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Michael A. Smith updated AVRO-3118:
-----------------------------------
Description:
Hi,
based on [the AVRO documentation|https://avro.apache.org/docs/current/spec.html] 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:
{code:java}
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){code}
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:
{code:python}
...
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:
...
{code}
was:
Hi,
based on the AVRO documentation an empty string may also be used as a namespace to indicate the null namespace. ([https://avro.apache.org/docs/current/spec.html)]
The Python package doesn't do that. Following example will fail when parsing:
{code:java}
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){code}
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:
{code:java}
...
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:
...
{code}
> Namespace with empty string is not treated as null in Python API
> ----------------------------------------------------------------
>
> Key: AVRO-3118
> URL: https://issues.apache.org/jira/browse/AVRO-3118
> Project: Apache Avro
> Issue Type: Bug
> Components: python
> Affects Versions: 1.10.2
> Reporter: Frank Mieves
> Priority: Blocker
>
> Hi,
> based on [the AVRO documentation|https://avro.apache.org/docs/current/spec.html] 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:
> {code:java}
> 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){code}
> 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:
>
> {code:python}
> ...
> 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:
> ...
> {code}
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)