You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by Daniel Young <dw...@pm.me.INVALID> on 2023/04/25 22:23:19 UTC
Python Issue with Optional UUIDs
Hi,
I believe there is an issue with the python library supporting a schema with optional UUIDs.
The field should look like:
"fields": [
{
"name": "userId",
"type": [
"null",
{
"type": "string",
"logicalType": "uuid"
}
]
}
]
but currently that does not validate with a userId: None and gives a TypeError exception.
I believe the fix is to catch TypeError here: https://github.com/apache/avro/blob/master/lang/py/avro/schema.py#L1046 in the same way that ValueError is caught. Anything that doesn't match the appropriate UUID type is guaranteed to not be a UUID.
I didn't find this in the issue tracker.
Thanks,
Daniel Young
Re: Python Issue with Optional UUIDs
Posted by Martin Grigorov <mg...@apache.org>.
Hi Daniel,
Would you like to send a Pull Request with the fix and a test case ?
Thank you!
Martin
On Wed, Apr 26, 2023 at 8:13 AM Daniel Young <dw...@pm.me.invalid> wrote:
> Hi,
> I believe there is an issue with the python library supporting a schema
> with optional UUIDs.
> The field should look like:
>
> "fields": [
> {
> "name": "userId",
> "type": [
> "null",
> {
> "type": "string",
> "logicalType": "uuid"
> }
> ]
> }
>
> ]
>
> but currently that does not validate with a userId: None and gives a
> TypeError exception.
>
> I believe the fix is to catch TypeError here:
> https://github.com/apache/avro/blob/master/lang/py/avro/schema.py#L1046
> in the same way that ValueError is caught. Anything that doesn't match the
> appropriate UUID type is guaranteed to not be a UUID.
> I didn't find this in the issue tracker.
> Thanks,
> Daniel Young