-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Fixes serialization of array items in model_to_dict [python] #9153
Fixes serialization of array items in model_to_dict [python] #9153
Conversation
result[attr] = value | ||
else: | ||
res = [] | ||
for v in value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails to handle the case where v
is a dict
, i.e. a free-form object.
e.g. a spec like:
"type": "array",
"items": {
"type": "object",
"additionalProperties": true
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be a bug related to inline schema handling.
Is there a model made and used for that schema?
If so, we handle it with line 1225
Can you want to post an issue describing the problem that you've found? Or a PR fixing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points, I'm not sure if the codegen is wrong or if the model_to_dict
is just missing the specific case.
The generated client code I'm experiencing this issue with is: https://github.com/sajari/sdk-python/blob/6bf9c20e4a2639eaf9774d1770b6a7ac39ed33c0/sajari_client/model/batch_upsert_records_request.py#L130-L131
e.g. when I attempt to serialise my request like:
request = BatchUpsertRecordsRequest(
pipeline=BatchUpsertRecordsRequestPipeline(name="app", version="1"),
records=BatchUpsertRecordsRequestRecords([{"foo": "bar"}]),
variables={},
)
model_to_dict(request, serialize=True)
it fails with:
Traceback (most recent call last):
File "/Users/jsok/dev/github.com/sajari/sdk-python/test/test_reproduction.py", line 83, in test_request_serialisation
print(model_to_dict(request, serialize=True))
File "/Users/jsok/dev/github.com/sajari/sdk-python/sajari_client/model_utils.py", line 1693, in model_to_dict
res.append(model_to_dict(v, serialize=serialize))
File "/Users/jsok/dev/github.com/sajari/sdk-python/sajari_client/model_utils.py", line 1665, in model_to_dict
if model_instance._composed_schemas:
AttributeError: 'dict' object has no attribute '_composed_schemas'
Happy to contribute a PR that makes the fix in the model_to_dict
method if that's the right place for it.
Fixes serialization of array items in model_to_dict [python]
If merged, this will resolve #8770
Tests of serialization and deserialization have been added in:
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
,5.1.x
,6.0.x