Skip to content

Docs Schema referenced schema appears incorrect #864

@Amertz08

Description

@Amertz08

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() and confluent_kafka.libversion()):
  • Apache Kafka broker version:
  • Client configuration: {...}
  • Operating system:
  • Provide client logs (with 'debug': '..' as necessary)
  • Provide broker log excerpts
  • Critical issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy