Skip to content

Commit

Permalink
Fix validation for server_default
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Nov 24, 2023
1 parent eb8ccc3 commit bfd5bc7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions edgy/core/db/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def __init__(
default = None
if default is not Undefined:
self.default = default
if default is not None or self.server_default is not None:
if (
(default is not None)
and default != Undefined
or (self.server_default is not None and self.server_default != Undefined)
):
self.null = True

self.defaulf_factory: Optional[Callable[..., Any]] = kwargs.pop(
Expand Down Expand Up @@ -110,7 +114,15 @@ def is_required(self) -> bool:
return bool(required and not self.primary_key)

def raise_for_non_default(self, default: Any, server_default: Any) -> Any:
if not self.field_type == int and default is None and server_default is None:
has_default: bool = True
has_server_default: bool = True

if default is None or default is False:
has_default = False
if server_default is None or server_default is False:
has_server_default = False

if not self.field_type == int and not has_default and not has_server_default:
raise FieldDefinitionError(
"Primary keys other then IntegerField and BigIntegerField, must provide a default or a server_default."
)
Expand Down

0 comments on commit bfd5bc7

Please sign in to comment.