Skip to content
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

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

Open
Daniel-Vetter-Coverwhale opened this issue Apr 17, 2024 · 2 comments
Labels
python Python models, clients, and server interfaces

Comments

@Daniel-Vetter-Coverwhale
Copy link

Daniel-Vetter-Coverwhale commented Apr 17, 2024

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

@armandobelardo
Copy link
Collaborator

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 armandobelardo changed the title pydantic_confg version specifies v2, but imports are still v1 Support Pydantic V2 without leveraging import pydantic.v1 Apr 17, 2024
@armandobelardo armandobelardo added the python Python models, clients, and server interfaces label Apr 17, 2024
@armandobelardo armandobelardo changed the title Support Pydantic V2 without leveraging import pydantic.v1 [FR] Support Pydantic V2 without leveraging import pydantic.v1 Apr 17, 2024
@alexrejto
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Python models, clients, and server interfaces
Development

No branches or pull requests

4 participants