'How to pass additional parameter in firebase transaction method in Python

I am trying to create a transaction like this for real time firebase database:

tranRef = db.reference('all_items')
new_transRef = tranRef.transaction(updateDatabase)

My updateDatabase function looks like this:

def updateDatabase(current_value):
    print(type(current_value))
    return current_value

Here the current_value is data containing all the child nodes at root "all_items". This works fine.
What I want is to pass an additional argument to the updateDatabase say cartList which is a list of dictionaries. How should I do that? What I essentially want is a function that looks something like this:

def updateDatabase(current_value, cartList):
    print(type(current_value))
    return current_value

How should I pass the list in calling the function:

tranRef = db.reference('all_items')
new_transRef = tranRef.transaction( ## what should I write here ##)


Solution 1:[1]

I was also dealing with same problem and I solved it by using lambda:

extra_param = ['your cart list here']
tranRef = db.reference('all_items')
new_transRef = tranRef.transaction(lambda current_value: updateDatabase(current_value, extra_param))

You can then call the transaction method like this:

def updateDatabase(current_value, cartList):
    print(type(current_value))
    return current_value

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1