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

Add option to use original_schema in AvroModel.serialize() #712

Open
kamilglod opened this issue Aug 11, 2024 · 1 comment
Open

Add option to use original_schema in AvroModel.serialize() #712

kamilglod opened this issue Aug 11, 2024 · 1 comment

Comments

@kamilglod
Copy link

kamilglod commented Aug 11, 2024

Is your feature request related to a problem? Please describe.
I generate dataclass models from AVRO schema that other team provides, and I want to be sure that I'm generating AVRO data using exact same schema. So I'm building python instance and now I want to call .serialize() but it uses only auto-generated schema from model, there is no option to use original_schema

Describe the solution you'd like
It would be nice to have either separate method or flag as an argument of the .serialize() method, something like use_original_schema: bool = False (for me True should be default but it would break backward compatibility)

Describe alternatives you've considered
Creating helper function in my code that would be used alywas to serialize model:

def serialize(model: AvroModel) -> bytes:
    return serialization.serialize(
        model.asdict(standardize_factory=utils.standardize_custom_type),
        model.original_schema,
        serialization_type="avro",
    )
@marcosschroh
Copy link
Owner

Hi @kamilglod

I think adding a flag called use_original_schema: bool = False to serialize method is a good idea.

If the original_schema was included in class Meta and the flag was set to True then the original_schema will be used, any other combination will be the fallback schema.

Also, this new flag might have to be added to the deserialize, which requires a bit more of refinement because we can use already 2 schemas to deserialize (contained schema and writer schema)

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

2 participants