-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
OpenAPI discriminator field disapeared with pydantic v2.5 #8271
Comments
Thanks for reporting this. Looks like a bug! Marking with |
@sydney-runkle I would like to take this issue. Can you point me to where I should start looking ? |
Fantastic 😄! My first thought is that if this was changed in Additionally, you can probably focus on the JSON schema generation logic for a given model. Lmk if this helps, happy to elaborate more if needed! |
@BaptisteSaves I am getting the Please check the example and output below, and let me know if you are still getting the issue. Modified Example Code
Output from
|
I realize I forgot to mention the impacted generated yaml is the one we get from FastAPI, sorry. I managed to reproduce the problem with a simple example. The discriminator field in the generated OpenAPI only disapears if the This change of behavior happens when I change the Pydantic version from 2.3.0 to 2.5.0 without changing the FastApi version At this point, It seems Thanks for your help 🙏
|
@StrawHatDrag0n @BaptisteSaves, I think this is indeed an issue with |
@sydney-runkle Do you have a guess where this code might be in fastAPI ? |
I'm not sure. @Kludex, any ideas? |
@BaptisteSaves @sydney-runkle I am trying to create a toy project using the example code provided but I am not able to get the Below is the example code:
any ideas ? Edit: Ignore, just noticed that I was using |
@BaptisteSaves Can you show me how you create the YAML ? |
@StrawHatDrag0n Here is the file and env, I ran it with
pyproject.toml
|
@sydney-runkle I think I have found the issue. I see that when we create I think the issue is where we generate the schema here we add the For the example code: definition of I think the solution could be to delay the addition of root schema definition till all the children schemas are added to the core_schema. Let me know if this makes sense. PS: Can you assign me this issue ? |
Hello, until folks fix the deeper issue, I found a workaround if you can afford to have a base class. When you introduce the field that you'll discriminate on via a parent class, the discriminator seems to be retained(pydantic
|
@sydney-runkle I am not sure what the unit test for this change might be ? Should I just check against the the correct OpenAPI json ? If yes, then where should I add the unit test ? |
Thanks for the fix! Yep, if you could check against the correct JSON, that'd be great. The test_discriminated_union.py file would be best. I'll review tomorrow morning once you add the test. Thanks!! |
Going to reopen this. The fix used for this ended up breaking more important things, so we're going to revert that change and will need to find another workaround for this issue. |
Hi @sydney-runkle! Can you point me to where this change was causing issues? I will try to look for a work around. |
See this issue: #8689. Thanks! |
Hello @sydney-runkle @StrawHatDrag0n, Do you have any news for a possible fix on this regression 🙏 |
Not yet, though I'll take a closer look this week. This looks pretty related: #8628 |
Could you please verify that this issue is fixed on the |
Ah actually I think this isn't fixed by that change, though maybe that gets us a good start! |
@BaptisteSaves @StrawHatDrag0n, Is there a purely pydantic reproduction of this issue? |
@sydney-runkle I am not sure. Also the issue is linked to the usage of alias on the discriminator field. Without alias, the resultant OpenApi.yaml is correct |
Initial Checks
Description
Hello,
We are using pydantic V2 to generate the openapi schema.
We bumped pydantic from 2.3.0 to 2.5.2 and the discriminator field disappeared in the openapi.yaml.
2.3.0 openapi.yaml
2.5.2 openapi.yaml
--> the discriminator tag is not there anymore
Can you tell me if it is normal this field disappeared ?
Thanks a lot for your help
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: