-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
RecordField default_to_avro produces non serializable output #382
Comments
Maybe not so urgent as this one should think if a dynamic value such as the result of datetime.now (probably often a default_factory) is really what you want in the schema (changes every time it is generated) |
We are seeing the same issue with static Decimal fields. It stopped working on 0.45.0 -> 0.45.1 version change. Our schema:
The 'default' key of OrderedDict AVRO schema contains: which is not JSON serializable |
@michal-rogala what would you expect to happen? Parse as string into avro as it is more reliable than a float or render a float from decimal? Is the decimal type rendering a number? |
String is the most reliable way - I believe this issue is only about schema definition, right? I tested your fix and it works in our case too, but I didn't check what was the decimal representation there. |
I am sorry, checked avro spec and this projects spec and both are rendering it to bytes, I have no issues using decimal defaults. can you comment an example that raises? |
Yeah, I believe this bug can occur when there is a several nested records and the lowest one has a default decimal value. I tried to follow an execution trace and while individual sub-records schema are generated properly - the "stiched" final one has this issue. |
@dabdada ok, I did some testing and the problem happens when there is a default factory specified for a subrecord:
|
K thank you. Can you check if this is fixed by my branch as well? I do believe so |
yes, it seems so :) |
* fix: record fields avro schema creation (#382) * fix: render avro data types correctly for nested default values (#382) * fix: convert record field default values to avro compatable value (#382) * chore: use field_map to get recordfield value default (#382) --------- Co-authored-by: Marcos Schroh <2828842+marcosschroh@users.noreply.github.com>
Describe the bug
When having a nested model the avro_schema function of the model fails if the nested attribute contains a non json serializable field e.g. datetime.
To Reproduce
Expected behavior
Should produce the avor schema with default of datetime as string
As for my understanding it is due to
RecordField.default_to_avro
simply calling theto_dict
function on the value provided.As far as I can tell the
default_to_avro
is only called on rendering, so it should be fine to dojson.loads(value.to_json())
here.Edit: fixed suggested fix to use
to_json()
The text was updated successfully, but these errors were encountered: