Skip to content

Commit

Permalink
Merge pull request #144 from mauro-andre/143-dbmodel-initializes-empt…
Browse files Browse the repository at this point in the history
…y-lists-as-none-causing-validationerror

🐛 DbModel initialize empty lists
  • Loading branch information
mauro-andre authored Jul 29, 2024
2 parents 5363040 + 432a810 commit 2aa052c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pyodmongo/models/db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def __init__(self, **attrs):
try:
default_value = self.__class__.model_fields[key].default
attrs[key] = (
None
if default_value == PydanticUndefined
else default_value
[] if default_value == PydanticUndefined else default_value
)
except KeyError:
...
Expand Down
7 changes: 7 additions & 0 deletions tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,10 @@ class SecondClass(FirstClass):
assert type(obj_1.attr_1) is str
assert obj_2.attr_1 == 1
assert type(obj_2.attr_1) is int


def test_empty_list_field():
class A(DbModel):
x: list[int]

A(x=[])

0 comments on commit 2aa052c

Please sign in to comment.