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

Bug on update with transaction, with complex model #151

Open R4Ajeti opened 2 years ago

R4Ajeti commented 2 years ago

image

AxeemHaider commented 2 years ago

Please provide the code what you are trying to do

R4Ajeti commented 2 years ago

image


def put_on_transaction_endpoint_generic(transaction=None, model_dict=None, entity_name=None, key=None, *args, **kwargs):
    transaction = fireo.transaction()
    entities = eval(entity_name).collection.get(key)

    if not entities and model_dict:
        for attr in model_dict.keys():
            if not attr in ['id', 'key', 'entity_id']:
                if attr == 'location':
                    setattr(entities, attr, fireo.GeoPoint(latitude=model_dict[attr]['latitude'], longitude=model_dict[attr]['longitude']))
                else:
                    setattr(entities, attr, model_dict[attr])
    entities = entities.update(transaction=transaction)
    return entities```

  '''
   in my model i have included:
   TextField, NumberField, MapField, DateTimeField, IDField, BooleanField
   but i cannot share it
   '''
R4Ajeti commented 2 years ago

Hi, @AxeemHaider Are update and save methods reserved keywords? I dont see them here: https://octabyte.io/FireO/reserved-words/ I figure it out where is the problem of this bug: USE CASE 1 - update key: if you use "update" as key of your model and you try to save your model it will work, later on when you try to update and key of this doc you will be getting this error 'dict' object is not callable ( its a conflict with fireo update method ) USE CASE 2 - save key: if you try to save a model that has save key on it you will be getting the error that document is not created

P.S. I use this methods for post and put request MyModel.save(merge=True) and MyModel.update(transaction=transaction)

Happy coding, Rino