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

Fixes serialization of array items in model_to_dict [python] #9153

Merged

Conversation

spacether
Copy link
Contributor

@spacether spacether commented Apr 1, 2021

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:

  • test_get_inline_additional_properties_ref_payload
  • test_get_inline_additional_properties_payload

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    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.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@spacether spacether marked this pull request as draft April 1, 2021 16:59
@spacether spacether changed the title Adds tests of endpoint with inline and refed model Fixes serialization of array items in model_to_dict [python] Apr 1, 2021
@spacether spacether marked this pull request as ready for review April 1, 2021 17:10
@spacether spacether added this to the 5.1.1 milestone Apr 1, 2021
@spacether spacether merged commit fc58ade into OpenAPITools:master Apr 1, 2021
@spacether spacether deleted the fix_python_model_to_dict_issue8770 branch April 1, 2021 20:34
result[attr] = value
else:
res = []
for v in value:
Copy link

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
        },

Copy link
Contributor Author

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?

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants