{"action":"created","issue":{"url":"https://api.github.com/repos/flix-tech/avro-php/issues/2","repository_url":"https://api.github.com/repos/flix-tech/avro-php","labels_url":"https://api.github.com/repos/flix-tech/avro-php/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/flix-tech/avro-php/issues/2/comments","events_url":"https://api.github.com/repos/flix-tech/avro-php/issues/2/events","html_url":"https://github.com/flix-tech/avro-php/pull/2","id":376372237,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI3NjAzMTk5","number":2,"title":"Ensured null default is normalized","user":{"login":"gquemener","id":668604,"node_id":"MDQ6VXNlcjY2ODYwNA==","avatar_url":"https://avatars1.githubusercontent.com/u/668604?v=4","gravatar_id":"","url":"https://api.github.com/users/gquemener","html_url":"https://github.com/gquemener","followers_url":"https://api.github.com/users/gquemener/followers","following_url":"https://api.github.com/users/gquemener/following{/other_user}","gists_url":"https://api.github.com/users/gquemener/gists{/gist_id}","starred_url":"https://api.github.com/users/gquemener/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gquemener/subscriptions","organizations_url":"https://api.github.com/users/gquemener/orgs","repos_url":"https://api.github.com/users/gquemener/repos","events_url":"https://api.github.com/users/gquemener/events{/privacy}","received_events_url":"https://api.github.com/users/gquemener/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-11-01T12:27:52Z","updated_at":"2018-11-05T10:03:08Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/flix-tech/avro-php/pulls/2","html_url":"https://github.com/flix-tech/avro-php/pull/2","diff_url":"https://github.com/flix-tech/avro-php/pull/2.diff","patch_url":"https://github.com/flix-tech/avro-php/pull/2.patch"},"body":"I encountered an incompatible error when upgrading a schema using `\"flix-tech/avro-serde-php\": \"^1.1\"`, whereas the upgrade was totally fine when performing it through curl.\r\n\r\nIt appears that this is related to an issue in how the php lib normalizes the schema, and how it normalizes default null value in particular.\r\n\r\nHere's an example.\r\n\r\nLet's say that this schema is registered under the subject `foo-value`:\r\n```json\r\n{\r\n  \"type\": \"record\",\r\n  \"name\": \"foo\",\r\n  \"namespace\": \"com.landoop\",\r\n  \"fields\": [\r\n    {\r\n      \"name\": \"name\",\r\n      \"type\": \"string\"\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\nIf I register the following new version, it should work (because it is backward compatible):\r\n```json\r\n{\r\n  \"type\": \"record\",\r\n  \"name\": \"foo\",\r\n  \"namespace\": \"com.landoop\",\r\n  \"fields\": [\r\n    {\r\n      \"name\": \"name\",\r\n      \"type\": \"string\"\r\n    },\r\n    {\r\n      \"name\": \"email\",\r\n      \"type\": [\"null\", \"string\"],\r\n      \"default\": null\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\nBut it fails, with the following error:\r\n```\r\nFatal error: Uncaught FlixTech\\SchemaRegistryApi\\Exception\\IncompatibleAvroSchemaException: Schema being registered is incompatible with an earlier schema in /app/vendor/flix-tech/confluent-schema-registry-api/s\r\nrc/Exception/ExceptionMap.php on line 95\r\n```\r\n\r\nI discovered that the posted payload is not the one that I provided to the `AvroSchema::parse` method, but it is stripped from all default values!\r\n\r\nAfter investigation, it appears that the error lies in how the fields are normalized back, null default values will be ignored and the schema registry sees that as a BC break.\r\n\r\nThe PR specifically fixes this issue.\r\n\r\nWhat I don't understand is that, as the `email` field is an `union` type, its **default** default value should be the one of the first schema[1], here being `\"null\"` (which default value is `null`), so it shouldn't be necessary to specify this default value.\r\n\r\nMaybe the error lies in the schema registry after all? :thinking: \r\n\r\nEDIT: I'm running [confluentinc/cp-schema-registry:5.0.0-1](https://hub.docker.com/r/confluentinc/cp-schema-registry/)\r\n\r\n[1]  Default values for union fields correspond to the first schema in the union. https://avro.apache.org/docs/1.8.1/spec.html#schema_complex"},"comment":{"url":"https://api.github.com/repos/flix-tech/avro-php/issues/comments/435819090","html_url":"https://github.com/flix-tech/avro-php/pull/2#issuecomment-435819090","issue_url":"https://api.github.com/repos/flix-tech/avro-php/issues/2","id":435819090,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTgxOTA5MA==","user":{"login":"tPl0ch","id":115348,"node_id":"MDQ6VXNlcjExNTM0OA==","avatar_url":"https://avatars0.githubusercontent.com/u/115348?v=4","gravatar_id":"","url":"https://api.github.com/users/tPl0ch","html_url":"https://github.com/tPl0ch","followers_url":"https://api.github.com/users/tPl0ch/followers","following_url":"https://api.github.com/users/tPl0ch/following{/other_user}","gists_url":"https://api.github.com/users/tPl0ch/gists{/gist_id}","starred_url":"https://api.github.com/users/tPl0ch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tPl0ch/subscriptions","organizations_url":"https://api.github.com/users/tPl0ch/orgs","repos_url":"https://api.github.com/users/tPl0ch/repos","events_url":"https://api.github.com/users/tPl0ch/events{/privacy}","received_events_url":"https://api.github.com/users/tPl0ch/received_events","type":"User","site_admin":false},"created_at":"2018-11-05T10:03:08Z","updated_at":"2018-11-05T10:03:08Z","author_association":"COLLABORATOR","body":"@gquemener Again, thanks for your contribution!\r\n\r\nI am just gonna link the same answer I gave to the other thread:\r\n\r\nhttps://github.com/flix-tech/avro-php/pull/3#issuecomment-435817617\r\n\r\nI'll try to come back as soon as I have validated it."}}
{"actor":{"display_login":"tPl0ch"}}