Skip to content

Commit

Permalink
Fix pydantic serializer warnings (#31) (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
worldworm authored May 24, 2024
1 parent 8011849 commit 8b7f6f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

from pathlib import Path
from typing import Dict, List
from typing import Dict, List, Union

from pydantic import Field
from pydantic.v1.fields import Undefined
Expand All @@ -26,7 +26,7 @@

class DatabaseSettings(BaseDBConfig):
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
default: str = Field(
default: Union[str, Dict] = Field(
default=str(f"sqlite:///{BASE_DIR}/db.sqlite3"),
validation_alias="DATABASE_URL",
conn_max_age=0,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_db_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Optional
from typing import Dict, Optional, Union

from pydantic import Field, PostgresDsn
from pydantic_settings import BaseSettings, SettingsConfigDict
Expand All @@ -9,7 +9,7 @@

def test_empty():
class DatabaseConfig(BaseDBConfig):
default: Optional[PostgresDsn] = None
default: Union[Optional[PostgresDsn], Dict] = None
replica: Optional[Dict] = None

db_settings = DatabaseConfig()
Expand Down Expand Up @@ -97,7 +97,7 @@ class DatabaseConfig(BaseDBConfig):

def test_dsn_and_exact_config():
class DatabaseConfig(BaseDBConfig):
default: str = Field(default="postgres://user:password@hostname:5432/dbname")
default: Union[str, Dict] = Field(default="postgres://user:password@hostname:5432/dbname")
replica: PostgresDB = PostgresDB()

db_settings = DatabaseConfig()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_to_django.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List
from typing import Any, Dict, List, Union

from deepdiff import DeepDiff
from pydantic import Field, PostgresDsn, SecretStr, ValidationInfo, computed_field, field_validator
Expand All @@ -9,7 +9,7 @@

def test_to_django_settings():
class DatabaseConfig(BaseDBConfig):
default: PostgresDsn = Field(
default: Union[PostgresDsn, Dict] = Field(
default="postgres://user:password@hostname:5432/dbname",
validation_alias="DATABASE_URL",
)
Expand Down

0 comments on commit 8b7f6f9

Please # to comment.