octabytes / FireO

Google Cloud Firestore modern and simplest convenient ORM package in Python. FireO is specifically designed for the Google's Firestore
https://fireo.octabyte.io
Apache License 2.0
250 stars 30 forks source link

Bug on update model with nested model #179

Closed ADR-007 closed 1 year ago

ADR-007 commented 1 year ago

The update method doesn't work correctly with a nested model.

from fireo.fields import NestedModel, TextField
from fireo.models import Model

class MyNestedModel(Model):
    my_nested_field = TextField()

class MyModel(Model):
    my_field = TextField()
    my_nested_model = NestedModel(MyNestedModel)

def test_update():
    model = MyModel(
        my_field='my_field',
        my_nested_model=dict(my_nested_field='my_nested_field')
    )
    model.save()

    model_from_db = MyModel.collection.get(model.key)

    # this works
    assert model_from_db.my_field == 'my_field'
    assert model_from_db.my_nested_model.my_nested_field == 'my_nested_field'

    MyModel(my_field='new value').update(model.key)
    model_from_db = MyModel.collection.get(model.key)

    assert model_from_db.my_field == 'new value'
    assert model_from_db.my_nested_model.my_nested_field == 'my_nested_field'
    # Expected: 'my_nested_field'
    # Actual: None
ADR-007 commented 1 year ago

Fixed here