Firebase cloud function not triggering when deleting in transaction

413 views Asked by At

in my Android app I'm deleting some data from my Firebase Database tree, in a transaction because I want to delete multiple paths from the tree at the same time. The path that is deleted in a transaction is the following:

pseudocode:

begin transaction
for all eventId's in a list delete member with memberid
/contexts/uid/contextId/events/eventId/members/memberId
end for

then delete member from
/contexts/uid/contextId/members/memberId
commit

end transaction

I use the following java code in my android app and it works very well

 database.getReference(Global.DEV_PREFIX).runTransaction(new Transaction.Handler() {
            @Override
            public Transaction.Result doTransaction(MutableData mutableData) {

                for (String eventKey : eventKeySet) {
                    mutableData.child("/contexts/" + getCurrentUserId() + "/" + contextId + "/events/" + eventKey + "/members/" + member.getId()).setValue(null);
                }

                mutableData.child("/contexts/" + getCurrentUserId() + "/" + contextId + "/members/" + member.getId()).setValue(null);
                return Transaction.success(mutableData);
            }

            @Override
            public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {

                if (databaseError == null) {
                    callback.onSucess();
                } else {
                    callback.onError(databaseError);
                }
            }
        });

But now I want to have a cloud function that listens on the deletion of the member and deletes some files from the storage.

I did a lot of tests and I can not understand the behaviour. The cloud functions are triggered when deleting the member in a non transactional way. But when deleting in a transaction, the .onDelete event is never triggered in the server (nor the onWrite event). My Cloud function is defined in the following way:

exports.memberDeleteTrigerTest = functions.database.ref('/contexts/{userId}/{contextId}/members/{memberId}/')
    .onDelete(event => {

console.log('Hello memberDeleteTrigerTest');

return ;
});

I tried to listen to a inner property of the member without success:

exports.memberDeleteTrigerTest = functions.database.ref('/contexts/{userId}/{contextId}/members/{memberId}/id')
    .onDelete(event => {

console.log('Hello memberDeleteTrigerTest');

return ;
});

Maybe the way I delete the data in the transaction in the Android app is not the appropriate. Do you have any suggestions?

Thanks in advance

0

There are 0 answers