excludee null fields in _construct_relations (#870)
* excludee null fields in _construct_relations * add missing test to check empty relation in construct Co-authored-by: collerek <collerek@gmail.com>
This commit is contained in:
@ -859,6 +859,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
|||||||
relation_value = [
|
relation_value = [
|
||||||
relation_field.expand_relationship(x, model, to_register=False)
|
relation_field.expand_relationship(x, model, to_register=False)
|
||||||
for x in value_to_set
|
for x in value_to_set
|
||||||
|
if x is not None
|
||||||
]
|
]
|
||||||
|
|
||||||
for child in relation_value:
|
for child in relation_value:
|
||||||
|
|||||||
@ -60,6 +60,16 @@ def create_test_database():
|
|||||||
metadata.drop_all(engine)
|
metadata.drop_all(engine)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_construct_with_empty_relation():
|
||||||
|
async with database:
|
||||||
|
async with database.transaction(force_rollback=True):
|
||||||
|
hq = await HQ.objects.create(name="Main")
|
||||||
|
comp = Company(name="Banzai", hq=None, founded=1988)
|
||||||
|
comp2 = Company.construct(**dict(name="Banzai", hq=None, founded=1988))
|
||||||
|
assert comp.dict() == comp2.dict()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_init_and_construct_has_same_effect():
|
async def test_init_and_construct_has_same_effect():
|
||||||
async with database:
|
async with database:
|
||||||
|
|||||||
Reference in New Issue
Block a user