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

Preparing for Pydantic v2 release #532

Open
8 tasks done
bpenteado opened this issue Jan 18, 2023 · 14 comments
Open
8 tasks done

Preparing for Pydantic v2 release #532

bpenteado opened this issue Jan 18, 2023 · 14 comments
Labels
question Further information is requested

Comments

@bpenteado
Copy link

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

# any sqlmodel code is ok, providing that the development version of Pydantic v2 is installed (local or direct repo installation)

import SQLModel

Description

After locally installing Pydantic v2 (main development branch)... :

>> python -c "import pydantic; print(pydantic.__version__)"
2.0.0.dev0

... SQLModel breaks at import time:

>> python -c "import sqlmodel"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/bpenteado/opt/miniconda3/envs/lamin-dev/lib/python3.9/site-packages/sqlmodel/__init__.py", line 137, in <module>
    from .main import SQLModel as SQLModel
  File "/Users/bpenteado/opt/miniconda3/envs/lamin-dev/lib/python3.9/site-packages/sqlmodel/main.py", line 27, in <module>
    from pydantic.errors import ConfigError, DictError
ImportError: cannot import name 'ConfigError' from 'pydantic.errors' (/Users/bpenteado/laminlabs/pydantic/pydantic/errors.py)

Is there any roadmap or planning for preparing SQLModel for Pydantic V2?

This is not a request per se, but a simple inquiry as was done in the two issues below. Hopefully it serves as a watcher/tracker for this key transition:

Operating System

Linux, Windows, macOS, Other

Operating System Details

No response

SQLModel Version

0.0.8

Python Version

3.9.12

Additional Context

No response

@bpenteado bpenteado added the question Further information is requested label Jan 18, 2023
@antont
Copy link

antont commented Jun 19, 2023

FastAPI's Pydantic v2 support seems quite complete now, the CI now runs both with v1 and v2. I didn't look very closely, but all tests seem to pass.

Perhaps now is a good time to check how it would go with SQLModel and Pydantic v2. Has anyone taken a look?

fastapi/fastapi#9688

There's a migration guide at https://docs.pydantic.dev/dev-v2/migration/

@lfvarela
Copy link

lfvarela commented Jul 6, 2023

Is there an ETA for this?

@antont
Copy link

antont commented Jul 11, 2023

Is there an ETA for this?

Tiangolo has worked hard to bring FastAPI over to Pydantic v2. That's pretty far, and there he says, 4d ago, that he'll update SQLModel next. fastapi/fastapi#9709 (reply in thread)

@honglei
Copy link

honglei commented Aug 12, 2023

Some suggestions:

1, support sqlalchemy mapped_column(), Mapped or Column and lambda to avoid column object already assigned to table

2, support pydantic v2 types and network types

3, support Annotated types or more...

4, Open a new branch for pydantic v2 and sqlalchemy v2 instead of
#632

samples:

from sqlmodel import SQLModel, Field
from typing_extensions import Annotated
from typing import Optional
from pydantic import AnyUrl, UrlConstraints
from pydantic.main import BaseModel
MoveSharedUrl =  Annotated[AnyUrl, UrlConstraints(max_length=512, allowed_schemes=['smb', 'ftp','file'])]

from sqlalchemy import Integer, Column, String
from sqlalchemy.orm import mapped_column
from ipaddress import IPv4Address, IPv6Address

class Sample(SQLModel, table=True):
    #1,
    union_str : str | None = Field( description='the name', primary_key=True)
    
    #2,
    optional_str: Optional[str] = Field( )
    
    #3, annotated Field with default value
    rateMax: Annotated[int , Field( sa_column= lambda: Column(Integer, default=-1, server_default="-1", nullable=False), ge=-1, description="")] = -1
    
    #4, pydantic annotated AnyUrl
    annotated_url: MoveSharedUrl = Field(description='the url')
    union_annotated_url: MoveSharedUrl |None = Field(description='the url')
    #5, python type to sqlalchemy type
    source_ip: IPv4Address | IPv6Address = Field(
        sa_column=mapped_column(String),
        description="source IP"
    )

@honglei
Copy link

honglei commented Aug 12, 2023

A pull has been made for supporting my sample: mbsantiago#1

@gnthibault
Copy link

I Is there a release date for sqlmodel fully compatible with latest version (>2) of pydantic ?

@AntonDeMeester
Copy link
Contributor

I Is there a release date for sqlmodel fully compatible with latest version (>2) of pydantic ?

Is there an ETA for this?

Tiangolo has worked hard to bring FastAPI over to Pydantic v2. That's pretty far, and there he says, 4d ago, that he'll update SQLModel next. tiangolo/fastapi#9709 (reply in thread)

Not yet, but it's on his todo list

@farridav
Copy link

Any movement on this ? Thanks for great work so far

@9hgg
Copy link

9hgg commented Oct 1, 2023

Hi there,
@tiangolo can we help you on this transition ? What could save you some time here ?
Pydantic V2 is useful independently of SQLModel but any project with SQLModel is stuck behind.

@andrewshvv
Copy link

From #654

This is a tentative roadmap, I will update it as things evolve. Some things might be discarded, others might be added later. I didn't want to make it fully public as it could raise expectations, but it seems it would be more beneficial for the community to know all the ideas and objectives.

Now, here's the current high-level tentative roadmap:

Support for the latest SQLAlchemy before 2.0.
Support for SQLAlchemy 2.0.
Support for Pydantic 2.0.

@pmithrandir
Copy link

Maybe a silly idea, but in order to liberate the people using sqlmodel to use pydantic V2 on other part of the application, could you make the transition to use the embeded v1 present in V2 ?

That would allow dev to import pydantic V2, but to keep sqlmodel connected to pydantic V1 until it's ready.

@AntonDeMeester
Copy link
Contributor

@pmithrandir @tiangolo has fixed this and both support is now integrated in the master branch. So you can use v2 for everything now

@JBorrow
Copy link

JBorrow commented Jan 11, 2024

Should this issue not be closed now that v0.0.14 is out and supports pydantic v2?

@rcaught
Copy link

rcaught commented Oct 27, 2024

#735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests