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

Original schema not guaranteed to match generated schema from models #544

Closed
bengels97 opened this issue Feb 16, 2024 · 5 comments
Closed

Comments

@bengels97
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Kafka ValueDeserializationError thrown when deserialising message using the generated schema from AvroModel.avro_schema(), due to a mismatch in between the original schema, retrieved from our schema registry, and the generated schema.

In short, the flow: original_schema -> generated_object -> generated_schema, will not always work, as compatibility between original_schema and generated_schema is not guaranteed.

See pictures in additional context.

Describe the solution you'd like
The easiest work-around would be to include the original schema inside the generated object. Should be relatively easy to implement, the schema is already passed to the ModelGenerator.render() method. This would prevent any mismatch to happen, as you are able to refer to the original schema in the resulting models.

A more generic approach: Make it possible to pass extra meta information to the ModelGenerator.render() method.

Describe alternatives you've considered

  1. Implement a temporary fix in our own codebase by modifying the resulting model_code string. But this would be prone to break, as the order of the generated models might not be guaranteed.

Additional context
The thrown error:
image

Cause of the error:
Original schema:
"fields": [{"name": "accumulation", "type": {"type": "enum", "name": "Accumulation_analog", "symbols": [ "Average", "Maximum", "Minimum", "Summation", "None"]}}]
Generated schema from model:
"fields": [{"name": "accumulation", "type": {"type": "enum", "name": "AccumulationAnalog", "symbols": ["Average", "Maximum", "Minimum", "Summation", "None"]}}]

@bengels97 bengels97 changed the title Original schema not guaranteed to match generated schema from models.Making the original schema string available in Message object Original schema not guaranteed to match generated schema from models Feb 16, 2024
@bengels97
Copy link
Contributor Author

I have prepared a local branch with a solution in place. Leveraging the ModelGenerator.metadata_field_templates attribute. I don't have the permissions to create remote branch here though.

Would like to be able to create a PR and get your thoughts on the implementation.

@marcosschroh
Copy link
Owner

HI @bengels97

Interesting case. Please send the PR and we can take a look. You can fork the repository and then send a PR from your fork

@bengels97
Copy link
Contributor Author

Appreciate the quick response @marcosschroh.

You can find the PR here: #545

@marcosschroh
Copy link
Owner

Mitigated by #545 but still we need a solution for fields with inner names

@marcosschroh
Copy link
Owner

@bengels97 After merging #544 this issue will be fixed. Hopefully you won't need anymore to have the original schema in your model.

@marcosschroh marcosschroh removed bug Something isn't working in progress labels Mar 28, 2024
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