mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Pydantic v2 migration
This commit is contained in:
1 parent
11f51b3809
commit
9c456532d0
46 files changed
+221
-277
No files matched your search
@@ -21,7 +21,7 @@ from fastapi.encoders import jsonable_encoder
|
||||
from sqlalchemy import Column, DateTime, func, inspect
|
||||
from sqlalchemy.types import TypeDecorator, CHAR, VARCHAR
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.ext.declarative import as_declarative
|
||||
from sqlalchemy.orm import as_declarative
|
||||
|
||||
|
||||
@as_declarative()
|
||||
|
||||
@@ -68,7 +68,7 @@ class ComputesRepository(BaseRepository):
|
||||
|
||||
async def update_compute(self, compute_id: UUID, compute_update: schemas.ComputeUpdate) -> Optional[models.Compute]:
|
||||
|
||||
update_values = compute_update.dict(exclude_unset=True)
|
||||
update_values = compute_update.model_dump(exclude_unset=True)
|
||||
|
||||
password = compute_update.password
|
||||
if password:
|
||||
|
||||
@@ -93,7 +93,7 @@ class RbacRepository(BaseRepository):
|
||||
Update a role.
|
||||
"""
|
||||
|
||||
update_values = role_update.dict(exclude_unset=True)
|
||||
update_values = role_update.model_dump(exclude_unset=True)
|
||||
query = update(models.Role).\
|
||||
where(models.Role.role_id == role_id).\
|
||||
values(update_values)
|
||||
@@ -236,7 +236,7 @@ class RbacRepository(BaseRepository):
|
||||
Update a permission.
|
||||
"""
|
||||
|
||||
update_values = permission_update.dict(exclude_unset=True)
|
||||
update_values = permission_update.model_dump(exclude_unset=True)
|
||||
query = update(models.Permission).\
|
||||
where(models.Permission.permission_id == permission_id).\
|
||||
values(update_values)
|
||||
|
||||
@@ -97,7 +97,7 @@ class UsersRepository(BaseRepository):
|
||||
Update an user.
|
||||
"""
|
||||
|
||||
update_values = user_update.dict(exclude_unset=True)
|
||||
update_values = user_update.model_dump(exclude_unset=True)
|
||||
password = update_values.pop("password", None)
|
||||
if password:
|
||||
update_values["hashed_password"] = self._auth_service.hash_password(password=password.get_secret_value())
|
||||
@@ -207,10 +207,10 @@ class UsersRepository(BaseRepository):
|
||||
user_group_update: schemas.UserGroupUpdate
|
||||
) -> Optional[models.UserGroup]:
|
||||
"""
|
||||
Update an user group.
|
||||
Update a user group.
|
||||
"""
|
||||
|
||||
update_values = user_group_update.dict(exclude_unset=True)
|
||||
update_values = user_group_update.model_dump(exclude_unset=True)
|
||||
query = update(models.UserGroup).\
|
||||
where(models.UserGroup.user_group_id == user_group_id).\
|
||||
values(update_values)
|
||||
@@ -224,7 +224,7 @@ class UsersRepository(BaseRepository):
|
||||
|
||||
async def delete_user_group(self, user_group_id: UUID) -> bool:
|
||||
"""
|
||||
Delete an user group.
|
||||
Delete a user group.
|
||||
"""
|
||||
|
||||
query = delete(models.UserGroup).where(models.UserGroup.user_group_id == user_group_id)
|
||||
|
||||
@@ -122,7 +122,7 @@ async def get_computes(app: FastAPI) -> List[dict]:
|
||||
db_computes = await ComputesRepository(db_session).get_computes()
|
||||
for db_compute in db_computes:
|
||||
try:
|
||||
compute = schemas.Compute.from_orm(db_compute)
|
||||
compute = schemas.Compute.model_validate(db_compute)
|
||||
except ValidationError as e:
|
||||
log.error(f"Could not load compute '{db_compute.compute_id}' from database: {e}")
|
||||
continue
|
||||
@@ -212,7 +212,7 @@ async def discover_images_on_filesystem(app: FastAPI):
|
||||
existing_image_paths = []
|
||||
for db_image in db_images:
|
||||
try:
|
||||
image = schemas.Image.from_orm(db_image)
|
||||
image = schemas.Image.model_validate(db_image)
|
||||
existing_image_paths.append(image.path)
|
||||
except ValidationError as e:
|
||||
log.error(f"Could not load image '{db_image.filename}' from database: {e}")
|
||||
|
||||
Reference in new issue
Block a user