fastapi-amis-admin
fastapi-amis-admin copied to clipboard
pydantic v2 migration problem?
/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/pydantic/_migration.py:282: UserWarning:
pydantic.utils:deep_update
has been removed. We are importing frompydantic.v1.utils:deep_update
instead.See the migration guide for more details: https://docs.pydantic.dev/latest/migration/ warnings.warn( Traceback (most recent call last): File "/Users/peter42/Documents/github/frontier/amis-admin/main.py", line 9, infrom fastapi_amis_admin.admin.settings import Settings File "/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/fastapi_amis_admin/admin/init.py", line 1, in from .admin import ( File "/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/fastapi_amis_admin/admin/admin.py", line 36, in from fastapi_amis_admin.admin.handlers import register_exception_handlers File "/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/fastapi_amis_admin/admin/handlers.py", line 18, in from fastapi_amis_admin.crud import BaseApiOut File "/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/fastapi_amis_admin/crud/init.py", line 3, in from ._sqlalchemy import SqlalchemyCrud, SqlalchemySelector File "/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/fastapi_amis_admin/crud/_sqlalchemy.py", line 30, in from fastapi_amis_admin.utils.pydantic import ( File "/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/fastapi_amis_admin/utils/pydantic.py", line 21, in from pydantic_settings import BaseSettings # noqa: F401 ModuleNotFoundError: No module named 'pydantic_settings'
When I try to run the sample from documentation, it seems that there are pydantic v2 migration issues not fixed in 0.6.1. Could you please have a look at my error output as above?
my pydantic env is as below:
pip show pydantic Name: pydantic Version: 2.0.3 Summary: Data validation using Python type hints Home-page: Author: Author-email: Samuel Colvin [email protected], Eric Jolibois [email protected], Hasan Ramezani [email protected], Adrian Garcia Badaracco [email protected], Terrence Dorsey [email protected], David Montague [email protected] License: Location: /Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages Requires: annotated-types, pydantic-core, typing-extensions Required-by: fastapi, fastapi_amis_admin
I got it. In pydantic v2, pydantic_settings was moved to serperate package, and I have to manually install it by 'pip install pydantic_settings'. The issue was solved.
In the example about FormAdmin in docs '''from fastapi_amis_admin.models.fields import Field
register FormAdmin
@site.register_admin class UserLoginFormAdmin(admin.FormAdmin): page_schema = 'UserLoginForm' # set form information, optional form = Form(title='This is a test login form', submitText='login')
# create form schema
class schema(BaseModel):
username: str = Field(..., title='username', min_length=3, max_length=30)
password: str = Field(..., title='password')
# handle form submission data
async def handle(self, request: Request, data: BaseModel, **kwargs) -> BaseApiOut[Any]:
if data.username == 'amisadmin' and data.password == 'amisadmin':
return BaseApiOut(msg='Login successfully!', data={'token': 'xxxxxx'})
return BaseApiOut(status=-1, msg='Incorrect username or password!')
''' However, pydantic.typing.NoArgAnyCallable was removed from pydantic v2 according to the migration guide of Pydantic site. And I got the error report Undefined type is not in pydantic.fields module. I checked pydantic v2 source code, it doesn't exsit there.
/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/pydantic/_migration.py:282: UserWarning:
pydantic.utils:deep_update
has been removed. We are importing frompydantic.v1.utils:deep_update
instead.See the migration guide for more details: https://docs.pydantic.dev/latest/migration/ warnings.warn( /Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/pydantic/_migration.py:282: UserWarning:pydantic.utils:smart_deepcopy
has been removed. We are importing frompydantic.v1.utils:smart_deepcopy
instead.See the migration guide for more details: https://docs.pydantic.dev/latest/migration/ warnings.warn( Traceback (most recent call last): File "/Users/peter42/Documents/github/frontier/amis-admin/main.py", line 14, infrom fastapi_amis_admin.models.fields import Field File "/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/fastapi_amis_admin/models/fields.py", line 3, in from pydantic.fields import Undefined, UndefinedType ImportError: cannot import name 'Undefined' from 'pydantic.fields' (/Users/peter42/opt/miniconda3/envs/pydant2/lib/python3.10/site-packages/pydantic/fields.py)
sqlmodel not support Pydantic V2 yet, pain
Better support for pydantic v2 is available starting with v0.7.0