Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems reading schema with namespaces #84

Open
pkowalski700lm opened this issue Aug 16, 2024 · 0 comments
Open

Problems reading schema with namespaces #84

pkowalski700lm opened this issue Aug 16, 2024 · 0 comments

Comments

@pkowalski700lm
Copy link

pkowalski700lm commented Aug 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant