fern icon indicating copy to clipboard operation
fern copied to clipboard

[FR] Support Pydantic V2 without leveraging `import pydantic.v1`

Open Daniel-Vetter-Coverwhale opened this issue 10 months ago • 2 comments

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

image

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.

armandobelardo avatar Apr 17 '24 16:04 armandobelardo

👋 Hey Fern team! We are also hung up on this issue so would love to talk about what an upgrade path would look like.

alexrejto avatar May 14 '24 20:05 alexrejto

Hey @armandobelardo - Is there any update on this thread? We would love to test this out and upgrade pydantic.

alexrejto avatar Jul 15 '24 19:07 alexrejto

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

armandobelardo avatar Jul 30 '24 10:07 armandobelardo