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
249 stars 29 forks source link

2.0.0 migration problem from 1.7.0 #200

Open Chetchaiyan opened 1 year ago

Chetchaiyan commented 1 year ago

Dear All, I found the error during migrate to v2.0.0 so at the moment I stuck with v1.7.0

The error appear in case of I mix up models with instance variable eg.

Class A(models.Model):
    a = models.TextField()

    def init(self):
        self._a = "Hello World"

when save() _a has been evaluated as field variable.

ADR-007 commented 1 year ago

Hi @Chetchaiyan Could you please provide more information about your case? A minimal test case would be perfect. I just tried the next and don't see any problems:

from fireo import db
from fireo.fields import TextField
from fireo.models import Model

class A(Model):
    a = TextField()

def test_extra_fields():
    a = A()
    a.a = 'a'
    a._a = '_a'
    a.save()

    assert db.conn.document(a.key).get().to_dict() == {'a': 'a'}
Chetchaiyan commented 1 year ago

Sorry, I can't come up with minimal case. I will do my best. However, in the mean time, Please consider the following error as a clue.

def __setattr__(self, key, value):
        """Keep track which filed values are changed"""
        if key in self._meta.field_list:
>           self._field_changed.add(key)
E           AttributeError: 'NoneType' object has no attribute 'add'

../../anaconda3/envs/py11/lib/python3.11/site-packages/fireo/models/model.py:535: AttributeError
ADR-007 commented 1 year ago

I suppose, you override __init__ but forgot to call super().__init__(**kwargs) inside it. So, please, try to add it to the beginning of your method.