Skip to content

Commit c84c844

Browse files
michaelstoopsMichael Stoops
andauthored
Fix 'default and default_for_new' check (pynamodb#1170)
Co-authored-by: Michael Stoops <[email protected]>
1 parent b5600ea commit c84c844

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pynamodb/attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(
111111
default_for_new: Optional[Union[Any, Callable[..., _T]]] = None,
112112
attr_name: Optional[str] = None,
113113
) -> None:
114-
if default and default_for_new:
114+
if default is not None and default_for_new is not None:
115115
raise ValueError("An attribute cannot have both default and default_for_new parameters")
116116
if not callable(default) and not isinstance(default, _IMMUTABLE_TYPES):
117117
raise ValueError(

tests/test_attributes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ def test_default(self):
147147
Attribute(default=list)
148148
Attribute(default_for_new=list)
149149

150+
with pytest.raises(ValueError, match="An attribute cannot have both default and default_for_new parameters"):
151+
Attribute(default='test', default_for_new='test')
152+
153+
with pytest.raises(ValueError, match="An attribute cannot have both default and default_for_new parameters"):
154+
Attribute(default=False, default_for_new='test')
155+
156+
150157

151158
class TestUTCDateTimeAttribute:
152159
"""

0 commit comments

Comments
 (0)