-
Notifications
You must be signed in to change notification settings - Fork 919
Closed
Description
Description
The Schema
object docs show references
should be [Schema]
but I think it is actually supposed to be [SchemaReference]
.
If you use Schema
then attempt to use SchemaRegistry.register_schema
it references attributes that do not exist.
# CP 5.5 adds new fields (for JSON and Protobuf).
if len(schema.references) > 0 or schema.schema_type != 'AVRO':
request['schemaType'] = schema.schema_type
request['references'] = [{'name': ref.name,
'subject': ref.subject,
'version': ref.version}
for ref in schema.references]
How to reproduce
import json
from confluent_kafka.schema_registry import SchemaRegistryClient, Schema, SchemaReference
from fastavro.schema import fullname
if __name__ == "__main__":
subject = "some-subject"
registry_url = "http://registry.blah"
client = SchemaRegistryClient({"url": registry_url})
with open("child.avsc", "r") as f:
schema_str = f.read()
child = Schema(schema_str, "AVRO")
child_id = client.register_schema(subject, child)
registered = client.lookup_schema(subject, child)
# name = fullname(json.loads(registered.schema.schema_str))
# referenced = SchemaReference(
# name=name,
# subject=subject,
# version=registered.version
# )
with open("parent.avsc", "r") as f:
schema_str = f.read()
parent = Schema(schema_str, "AVRO", [child])
# parent = Schema(schema_str, "AVRO", [referenced])
schema_id = client.register_schema("webhooks", parent)
print(schema_id)
Also it appears that the following logic might be incorrect.
if len(schema.references) > 0 or schema.schema_type != 'AVRO':
If I make the changes commented out in my example I can get passed the attribute error but I get an error from the API
confluent_kafka.schema_registry.error.SchemaRegistryError: Unrecognized field: schemaType (HTTP status code 422, SR code 422)
That being said it would be nice to have an example of how to register nested Avro schemas somewhere in the docs. We are having a rough time trying to figure it out.
Checklist
Please provide the following information:
confluent-kafka[avro]==1.4.1
librdkafk ('1.4.0', 17039615)
Mac OSX
confluentinc/cp-schema-registry:5.3.1
- confluent-kafka-python and librdkafka version (
confluent_kafka.version()
andconfluent_kafka.libversion()
): - Apache Kafka broker version:
- Client configuration:
{...}
- Operating system:
- Provide client logs (with
'debug': '..'
as necessary) - Provide broker log excerpts
- Critical issue
slominskir
Metadata
Metadata
Assignees
Labels
No labels