From 05ea366fd0d3ce27aeb65e93e6b2b19d90278cfc Mon Sep 17 00:00:00 2001 From: Andrey Lepekhin Date: Sun, 26 Nov 2023 18:25:44 +0300 Subject: [PATCH] Fix: Undefined import in demo app. Also improved format_config_from_dsn() readability --- demo/demo/settings.py | 2 +- pydjantic/pydjantic.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/demo/demo/settings.py b/demo/demo/settings.py index 26ff682..e227523 100644 --- a/demo/demo/settings.py +++ b/demo/demo/settings.py @@ -14,7 +14,7 @@ from typing import Dict, List from pydantic import Field -from pydantic.fields import Undefined +from pydantic.v1.fields import Undefined from pydantic_settings import BaseSettings, SettingsConfigDict from pydjantic import BaseDBConfig, to_django diff --git a/pydjantic/pydjantic.py b/pydjantic/pydjantic.py index aca40d6..0f17e1f 100644 --- a/pydjantic/pydjantic.py +++ b/pydjantic/pydjantic.py @@ -30,12 +30,11 @@ def format_config_from_dsn(cls, value: Any, info: ValidationInfo): if info.field_name: extra = cls.model_fields[info.field_name].json_schema_extra - if extra: + if isinstance(extra, dict): for kwarg in known_dj_database_url_kwargs: - if isinstance(extra, dict): - field_extra = extra.get(kwarg) - if field_extra is not None: - kwargs[kwarg] = field_extra + field_extra = extra.get(kwarg) + if field_extra is not None: + kwargs[kwarg] = field_extra return dj_database_url.parse(str(value), **kwargs)