-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Remove pydantic warnings when using model_dump as the default output is then overridden (#17939) #17941
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
Remove pydantic warnings when using model_dump as the default output is then overridden (#17939) #17941
Conversation
Can you help me on this PR 🙏 It says some tests are failing but without giving me which one, and everything is passing fine locally. |
I've restarted the failed jobs so let's see how that goes |
@BaptisteSaves : are you sure this still happens with 7.3.0? In #17511 I changed things related to how |
@multani Yes I am sure, I tested on 7.2, 7.3 and latest master jar. If you cannot reproduce with the OpenApi version I gave maybe It could be linked to specific version of Python and Pydantic V2 ? |
|
@BaptisteSaves Thanks, for the confirmation 👍 I also checked on my side and saw the issue as well. I think there could be a better fix than ignoring all the warnings (we adjusted lot of mypy/Pydantic settings in the past couple of months, there are probably still some problems) but I won't have time to look at it further this week. |
I checked the PR you linked and we can see this change in the
Testing locally the warning does not appear if I remove
I am lost on the impact of removing Also, could you explain the goal of this attribute |
@BaptisteSaves initially, using Pydantic v1, this was written as: any_of_schemas: List[str] = Field(xxx, const=True) In #16624, this was changed to: any_of_schemas: List[str] = Literal[xxx] because Pydantic was returning:
In #17511, this was changed to: any_of_schemas: List[str] = Field(default=Literal[xxx]) which is probably not super correct either. Retrospectively, we can remove Propositions@wing328 I'm also not super sure what's the purpose of I assumed this was some kind of "metadata" to give the indication which "schema" the class supports. Do you have more information about these fields and their purpose? Fixing "one of" fieldsFor "one of" field (for instance in the one_of_schema: Literal["X", "Y"] ... since I suppose the goal was to expose which model the underlying value is. The problem is that this field doesn't have a default value and is not set anywhere in the code. @wing328 is this a bug (the field should be set with a specific value and it doesn't) or is there another meaning behind this "one of" field? Fixing "any of" fieldsFor "any of" field (for instance in the @wing328 would it make sense to replace: any_of_schemas: List[str] = Field(default=Literal["X", Y"]) by: any_of_schemas: List[str] = Field(default=["X", Y"]) The previous version is incorrect anyway ( |
yes
please go ahead as I don't have a strong opinion on this. |
Thanks @wing328
Maybe not for this change here, but is it really necessary? Is it something that could be removed? |
At least any_of_schemas is not a single value, so it should not be a literal type. If literals are used correctly, it would look like this any_of_schemas: List[Literal["X", Y"]] = Field(default=["X", Y"]) Alternatively, you can use Set any_of_schemas: Set[str] = Set({"xxx", yyy"}) |
@BaptisteSaves I would say for now:
This way we can merge your change and remove the warnings and we can discuss afterwards how to improve these fields/constants . |
e2bfabd
to
a3f594f
Compare
a3f594f
to
4c7d835
Compare
4c7d835
to
623300c
Compare
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.
lgtm, thanks @BaptisteSaves !
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.
LGTM👍
@wing328 Can you merge the PR 🙏 ? |
just merged. thanks for the PR |
Looking forward to the release with this fix! We currently get lots of "Expected |
https://github.com/OpenAPITools/openapi-generator/milestones but may be delayed as we may have a few more changes we want to ship as part of the 7.5.0 release you may consider using the snapshot version for the time being (snapshot version can be found in the project's readme) |
Fixes #17939
Testes locally that the Pydantic warnings are not appearing anymore.
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
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)cc @cbornet @tomplus @krjakbrjak @fa0311 @multani