FireO icon indicating copy to clipboard operation
FireO copied to clipboard

Bug on update with transaction, with complex model

Open R4Ajeti opened this issue 3 years ago • 3 comments

image

R4Ajeti avatar Mar 03 '22 12:03 R4Ajeti

Please provide the code what you are trying to do

AxeemHaider avatar Mar 03 '22 13:03 AxeemHaider

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 avatar Mar 03 '22 14:03 R4Ajeti

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

R4Ajeti avatar Mar 04 '22 11:03 R4Ajeti