Skip to content

Problems reading schema with namespaces  #84

@pkowalski700lm

Description

@pkowalski700lm

Hello,

First of all thank you for development of this library, it helped us alot.

Issue is about version:

{
"name": "flix-tech/avro-serde-php",
            "version": "2.1.0",
            "source": {
                "type": "git",
                "url": "https://github.com/flix-tech/avro-serde-php.git",
                "reference": "ffeab369fe3631d2a076ef9744f0ee2dcab2238c"
            }
}

lock dependencies:

{
"name": "flix-tech/avro-php",
            "version": "5.0.1",
            "source": {
                "type": "git",
                "url": "https://github.com/flix-tech/avro-php.git",
                "reference": "85a78412e62a925fc2be73e7976902df6dfb3af7"
}
},

{
"name": "flix-tech/confluent-schema-registry-api",
            "version": "8.1.0",
            "source": {
                "type": "git",
                "url": "https://github.com/flix-tech/schema-registry-php-client.git",
                "reference": "87023aebb0393da62d932b9be49d0d891a52ae37"
}
}

This issue is really for library https://github.com/flix-tech/avro-php which is used by avro-serde-php. I wanted to put issue there, but it seems issues option is turned off there.

So basically, problem we encountered is with schemas, which have some records declared in one default namespace, and then, the record is also used in another. Library seems to parse it without errors, but after cacheing it (AvroSchema is casted to string in registry library) , and then reading this schema again it throws errors. For example schema is loaded without any problems with initial call to schema registry:

{
  "type": "record",
  "name": "POSLogRoot",
  "namespace": "org.nrf_arts.ixretail.namespace.avro",
  "fields": [
    {
      "name": "controlTransaction",
      "type": {
        "type": "record",
        "name": "ControlTransactionDomainSpecific",
        "fields": [
          {
            "name": "reasonCode",
            "type": [
              "null",
              {
                "type": "record",
                "name": "ReasonCodeCommonData",
                "fields": [
                  {
                    "name": "value",
                    "type": {
                      "type": "string",
                      "avro.java.string": "String"
                    }
                  },
                  {
                    "name": "_description",
                    "type": [
                      "null",
                      {
                        "type": "string",
                        "avro.java.string": "String"
                      }
                    ],
                    "default": null
                  }
                ]
              }
            ],
            "default": null
          }
        ]
      }
    },
    {
      "name": "tenderPickup",
      "type": [
        "null",
        {
          "type": "record",
          "name": "SettleTenderPickupBase",
          "namespace": "com.payment.data.repository.avro",
          "fields": [
            {
              "name": "reason",
              "type": [
                "null",
                "org.nrf_arts.ixretail.namespace.avro.ReasonCodeCommonData"
              ],
              "default": null
            }
          ]
        }
      ],
      "default": null
    }
  ]
}

In above example we can see ReasonCodeCommonData declared in default namespace org.nrf_arts.ixretail.namespace.avro.

It is also used in com.payment.data.repository.avro.SettleTenderPickupBase with full qualified name org.nrf_arts.ixretail.namespace.avro.ReasonCodeCommonData.

Now when we will cast $schema to string:

// $schema is object of type \AvroSchema from avro-php
(string) $schema

It produces:

{
  "type": "record",
  "name": "POSLogRoot",
  "namespace": "org.nrf_arts.ixretail.namespace.avro",
  "fields": [
    {
      "name": "controlTransaction",
      "type": {
        "type": "record",
        "name": "ControlTransactionDomainSpecific",
        "fields": [
          {
            "name": "reasonCode",
            "type": [
              {
                "type": "null"
              },
              {
                "type": "record",
                "name": "ReasonCodeCommonData",
                "fields": [
                  {
                    "name": "value",
                    "type": {
                      "type": "string"
                    }
                  },
                  {
                    "name": "_description",
                    "type": [
                      {
                        "type": "null"
                      },
                      {
                        "type": "string"
                      }
                    ],
                    "default": null
                  }
                ]
              }
            ],
            "default": null
          }
        ]
      }
    },
    {
      "name": "tenderPickup",
      "type": [
        {
          "type": "null"
        },
        {
          "type": "record",
          "name": "SettleTenderPickupBase",
          "namespace": "com.payment.data.repository.avro",
          "fields": [
            {
              "name": "reason",
              "type": [
                {
                  "type": "null"
                },
                "ReasonCodeCommonData"
              ],
              "default": null
            }
          ]
        }
      ],
      "default": null
    }
  ]
}

and above schema is wrong and below call will produce error:

// produces In schema.php line 398: ReasonCodeCommonData is not a schema we know about. 
\AvroSchema::parse($aboveSchemaContents)

Reason of error is of course missing namespace which was mentioned in original json, and cut out after casting to string ( org.nrf_arts.ixretail.namespace.avro.ReasonCodeCommonData ).

Casting to string is widely used in flix-tech/confluent-schema-registry-api , where schema is casted before cache'ing it.

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