Skip to content

WIP: fix json encoding#1

Open
mhoffm-aiven wants to merge 3 commits intomhoffm-fix-python-json-encodingfrom
mhoffm-refactor-python-io-to-fix-json-encoding
Open

WIP: fix json encoding#1
mhoffm-aiven wants to merge 3 commits intomhoffm-fix-python-json-encodingfrom
mhoffm-refactor-python-io-to-fix-json-encoding

Conversation

@mhoffm-aiven
Copy link
Owner

This PR fixes https://issues.apache.org/jira/browse/AVRO-1291 by adding proper json encoding capabilities to the python library.

Copy link

@dmitrii-vasilev dmitrii-vasilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments

class DatumReader:
"""Deserialize Avro-encoded data into a Python data structure."""

_writers_schema: Optional[avro.schema.Schema]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's copied but I think it's wrong because it defines type for a class attribute but it's an object attribute. Probably should be removed.

There is the same pattern in multiple places in this file.

Copy link

@hackaugusto hackaugusto Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is totally fine:

You can optionally declare instance variables in the class body

https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#classes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really confusing to me. Especially that the example is wrong here:

class MyClass:
    # This is an instance variable with a default value
    charge_percent: int = 100

It's still a class variable. It works here because the value is immutable. It won't work as expected if it will be something like items: List[int] = [100].

I wouldn't support that kind of confusion.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still a class variable. It works here because the value is immutable. It won't work as expected if it will be something like items: List[int] = [100].

There is not assignment here, it is just the type declaration PEP-0526.

You're totally correct that a mutable value things could be broken though.

raise avro.errors.SchemaResolutionException("Schemas do not match.", writers_schema, readers_schema)

if writers_schema.type == "null":
return None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even while returning None an encoder can potentially read something from the stream

Suggested change
return None
return decoder.read_null()

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

Successfully merging this pull request may close these issues.

3 participants