-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[BUG] [PYTHON] Generated client breaks on to_dict() method #10186
Comments
I think that it should be enough to modify the following file: |
We welcome PRs solving this issue.
So it's unclear if this issue still exists. |
OK, so I faced the issue this week, but I'm still investigating if the .yml i used as input for the code generator was well designed, or if the generator is really the one to blame. I'll leave another message as soon as I have figured that out, but in the meantime I'll give some feedback based on analysis of the generated code:
For now, I'll first try to rule out .yml issues (shit in, shit out rule always applies, right ;-)) |
I don't think that's true. My understanding is that |
I decided to try and produce some sort of failing test first (in the openapi generator python test cases). My long shot would be to call a to_dict() in one of the existing test cases that should cover the more "complex" datatypes produced by the code generator. However, a lot of the test cases I've found actually have empty bodies (e.g. in This makes it quite hard for me to judge if the flow described in the original ticket (calling to_dict() on some response) is actually covered in an existing test case or not. Maybe I should be looking at the more "integration level" test cases. I.e. the ones that mimic actual client-server interactions. I'll try that next. |
I am running into this issue and starting to debug it. My current assumption is that inline objects that are not defined at the top level (but instead at a lower level of the tree) have no model generated for them, and then become dicts instead of I am writing the OpenAPI spec for an existing API, and when I define parts of the response I receive from the server simply as That's my working assumption anyway. edit: I worked around it by completing our schema, so won't have cycles to debug this more. |
I also produced this with version 5.2.1. I upgrade to 5.3.1 and the error was immediately obvious to me. I had set a property as either (integer, nullable) but was receiving a string. At least in my case, it wasn't a bug, just good o'l user error and an un-helpful error message. |
Bug Report Checklist
Description
The .to_dict() function causes "AttributeError: 'dict' object has no attribute" error.
openapi-generator version
5.2.1
OpenAPI declaration file content or url
I used $ref with external files:
https://gist.github.com/Valmoz/16503c5ce996d27982722959733b6955
the paths are:
Generation Details
openapi-generator-cli generate -i openapi.yaml -g python -o generated/openapi/python/
Steps to reproduce
I tried to use the generated client from a dedicated python script:
When this code is executed, (more precisely: the to_dict() function) I obtain this error:
AttributeError: 'dict' object has no attribute '_composed_schemas'
Manually modifying the generated model_utils.py file at line 1634 (see next session), I was able to fix this error, but then I obtained another one:
AttributeError: 'dict' object has no attribute '_data_store'
Modifying also line 1640, I am able to retrieve:
Related issues/PRs
I didn't find any...
Suggest a fix
it seems possible to avoid the issues checking if model_instance contains the missing keys.
I modified the generated model_utils.py line 1634 as follows:
For the second error, I wrapped the for statement at line 1640 in an if statement as follows:
N.B.: I also noticed that lines 1652-1664 have been indented with one space less than the rest of the file (3 instead of 4)...
The text was updated successfully, but these errors were encountered: