Skip to content

Commit

Permalink
refactor: all but one deprecation warning eliminated (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeeva authored Apr 1, 2024
1 parent 320d605 commit 6ed6641
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
12 changes: 6 additions & 6 deletions pgbelt/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pgbelt.util.asyncfuncs import makedirs
from pydantic import BaseModel
from pydantic import ValidationError
from pydantic import validator
from pydantic import field_validator


def config_dir(db: str, dc: str) -> str:
Expand Down Expand Up @@ -37,7 +37,7 @@ class User(BaseModel):
name: str
pw: Optional[str] = None

_not_empty = validator("name", "pw", allow_reuse=True)(not_empty)
_not_empty = field_validator("name", "pw")(not_empty)


class DbConfig(BaseModel):
Expand All @@ -64,9 +64,9 @@ class DbConfig(BaseModel):
pglogical_user: User
other_users: Optional[list[User]] = None

_not_empty = validator("host", "ip", "db", "port", allow_reuse=True)(not_empty)
_not_empty = field_validator("host", "ip", "db", "port")(not_empty)

@validator("root_user", "owner_user", "pglogical_user")
@field_validator("root_user", "owner_user", "pglogical_user")
def has_password(cls, v) -> User: # noqa: N805
if not v.pw:
raise ValueError
Expand Down Expand Up @@ -118,7 +118,7 @@ class DbupgradeConfig(BaseModel):
sequences: Optional[list[str]] = None
schema_name: Optional[str] = "public"

_not_empty = validator("db", "dc", allow_reuse=True)(not_empty)
_not_empty = field_validator("db", "dc")(not_empty)

@property
def file(self) -> str:
Expand Down Expand Up @@ -167,7 +167,7 @@ async def load(cls, db: str, dc: str) -> Optional[DbupgradeConfig]:
return None

try:
out = cls.parse_raw(raw)
out = cls.model_validate_json(raw)
except ValidationError:
logger.info("Cached config was not a valid DbupgradeConfig")
return None
Expand Down
2 changes: 1 addition & 1 deletion pgbelt/config/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def load_remote_conf_def(
async with aopen(config_file, mode="r") as f:
raw_json = await f.read()

return RemoteConfigDefinition.parse_raw(raw_json)
return RemoteConfigDefinition.model_validate_json(raw_json)
except FileNotFoundError:
logger.error(f"No remote config definition exists at {config_file}")
except JSONDecodeError:
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from os import environ
from sys import argv
from shutil import rmtree

import pytest
import pytest_asyncio
import asyncio
from asyncpg import create_pool
Expand Down Expand Up @@ -216,7 +214,6 @@ async def _empty_out_databases(configs: dict[str, DbupgradeConfig]) -> None:
)


@pytest.mark.asyncio
@pytest_asyncio.fixture
async def setup_db_upgrade_configs():
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ async def _ensure_same_data(configs: dict[str, DbupgradeConfig]):
src_table_data[table] = src_table_data[table] + line + "\n"
elif len(src_table_data[table]) > 0:
src_table_data[table] = src_table_data[table] + line + "\n"
if line == "\.":
if line == "\\.":
break
dst_table_data = {}
for table in configs[setname].tables:
Expand All @@ -311,7 +311,7 @@ async def _ensure_same_data(configs: dict[str, DbupgradeConfig]):
dst_table_data[table] = dst_table_data[table] + line + "\n"
elif len(dst_table_data[table]) > 0:
dst_table_data[table] = dst_table_data[table] + line + "\n"
if line == "\.":
if line == "\\.":
break

# Ensure the targeted data is the same
Expand Down

0 comments on commit 6ed6641

Please sign in to comment.