[Python] Fix python template for list and dicts of dicts#23112
[Python] Fix python template for list and dicts of dicts#23112wing328 merged 3 commits intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/resources/python/model_generic.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/python/model_generic.mustache:375">
P1: `from_dict` crashes when map-of-map field is present but set to null. The condition `"{{{baseName}}}" in obj` only checks key presence, not value. If the input contains the key with explicit null value (valid for nullable properties), `obj["{{{baseName}}}"].items()` will raise `AttributeError: 'NoneType' object has no attribute 'items'`.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
modules/openapi-generator/src/main/resources/python/model_generic.mustache
Show resolved
Hide resolved
|
thanks for the fix can you please add a test schema to modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml and follow step 3 to regenerate the samples ? (please run the sample update command twice) |
|
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors. Let me know if you need help fixing it. |
41e3152 to
f501959
Compare
Thanks - I think I managed to fix it. |
f501959 to
7c1a8fd
Compare
@wing328 Thanks for the quick feedback. I added two test schemas - one is a dict of dicts with non-primitive types and the other one is a list of dicts. I also generated and added the samples. I think that the code generated by pydantic v1 is wrong (cf. https://github.com/OpenAPITools/openapi-generator/pull/23112/changes#diff-fda969d5c6bc4a395c4b0f943f87e8fd63bbe315e680336db016f1ffcec967b0R65) - to_dict is called on the values of a dict of dicts, i.e. on dicts that don't have this property. Should I fix this? And if yes, in this PR or separately? |
with a separate PR please |
|
cc @cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10) @multani (2023/10) |
I had some issues generating python code for dicts.
I made some changes to the corresponding template to fix these.
PR checklist
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*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Fixes Python generator templates to correctly handle lists of dicts and dicts of dicts, ensuring nested models in arrays/maps serialize to valid JSON and deserialize reliably. Adds spec fixtures, tests, and generated samples to cover arrays of maps and maps of maps.
Written for commit 7c1a8fd. Summary will update on new commits.