diff --git a/django2pydantic/getter.py b/django2pydantic/getter.py index d966a06..d177ca2 100644 --- a/django2pydantic/getter.py +++ b/django2pydantic/getter.py @@ -58,6 +58,10 @@ def _get_prefetched_values(self, key: str) -> Result: if k.startswith(f"{key}__"): values[k[len(key) + 2 :]] = v + # If values is empty, bubble up AttributeError as there's no value for the key + if not values: + raise AttributeError(key) + return values def __init__(self, obj: Any, schema_cls: Any, context: Any = None) -> None: diff --git a/django2pydantic/mixin.py b/django2pydantic/mixin.py index 1a480fe..825806d 100644 --- a/django2pydantic/mixin.py +++ b/django2pydantic/mixin.py @@ -18,7 +18,7 @@ class BaseMixins(BaseModel): "from_attributes": True, "arbitrary_types_allowed": True, "use_enum_values": True, - "validate_default": True, + "validate_default": False, } @model_validator(mode="wrap")