fern
fern copied to clipboard
[FR] Support Pydantic V2 without leveraging `import pydantic.v1`
Describe the bug
In my python generator config I specify pydantic version v2, but still wind up with pydantic.v1 imports.
To reproduce
Use the following generator config
default-group: local
groups:
local:
generators:
- name: fernapi/fern-python-sdk
version: 1.1.0-rc4
output:
location: local-file-system
path: ../python
config:
pydantic_config:
version: v2
client_class_name: WithterminalApi
Using 1.0.1 also has this issue, but I wanted to try with the latest to avoid the issue with a local unnecessary version file.
Grab any openapi you want, I'll attach one here as well.
Run fern generate. I do mine as
fern generat --local --log-level=debug
Look at any of the generated classes and see that the import statement is
import pydantic.v1 as pydantic
Expected behavior
import pydantic
Screenshots
CLI Version
The version of the Fern CLI you are using (found in fern.config.json
).
"version": "0.21.0"
Uploaded as txt as github won't allow me to upload yaml 🤷 openapi.txt
Hi there @Daniel-Vetter-Coverwhale this is currently intentional! This config just enforces the use of pydantic v2, so it's imports become import pydantic.v1 as pydantic
as opposed to import pydantic
for V1 or the conditional import we currently have if no config is specified.
if IS_PYDANTIC_V2:
import pydantic.v1 as pydantic_v1 # type: ignore # nopycln: import
else:
import pydantic as pydantic_v1 # type: ignore # nopycln: import
We plan to add support for pydantic v2 outright, as opposed to levaraging this conditional import, however that's still around a month+ out! I'll keep this open to update you once that's live.
👋 Hey Fern team! We are also hung up on this issue so would love to talk about what an upgrade path would look like.
Hey @armandobelardo - Is there any update on this thread? We would love to test this out and upgrade pydantic.
Hi there folks (@alexrejto @Daniel-Vetter-Coverwhale), as of version 3.0.0-rc0
the python generator supports v2 models and v1 models, depending on what you're running locally: https://github.com/fern-api/fern/blob/main/generators/python/sdk/CHANGELOG.md#300-rc0---2024-07-23