1

I am getting this error when a cloud function is executed:

Error: TRIGGER_PAYLOAD_TOO_LARGE: This request would cause a function payload exceeding the maximum size allowed.

This is the cloud function causing the error:

exports.inyectSerie = functions.database.ref('forms/{pushId}').onCreate(event => {
    if (!admin.apps.length) {
        admin.initializeApp();
    }
    var form = event.val();
    var formData = {
        serie: form.serie
    };
    admin.database().ref('series/'+form.serie).set(formData);
});

How do I know this is the function causing the error? I removed all cloud functions from my firebase and it worked as expected. Then I put back this inyectSerie function and it gave me the error again.

This is my firebase structure, being "medidores" node the one with the most data, with 150k records (which doesn't sound like a lot to me):

+fallidas
+forms <-- This has only 20 records
+materiales
+medidores <-- This has 150,000+ records
+series
+users

If you notice, medidores node is never touched on the cloud function.

I searched for the error and only found this other question reporting it, but I think the cloud function causing the problem on that case did access all the records on the db.

The only thing that comes to my mind to be the problem on my case, is that functions.database loads the whole database no matter what.


UPDATE: Even after reducing my trigger to a bare minimum (thanks, James Poag), I am getting the same error.

exports.inyectSerie = functions.database.ref('forms/{pushId}').onCreate(event => {
    return null;
});
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Multitut
  • 2,089
  • 7
  • 39
  • 63
  • 1
    You should return the last statement which is a promise. Perform some checks that `form.serie` exists and is a string and not an object. Also, you don't need the `formData` intermediate object if you are just setting a subkey, you are essentially doing: `return admin.database().ref(`series/${form.serie}/serie`).set(form.serie)` which seems a bit redundant... – James Poag Sep 13 '18 at 13:13
  • Thanks, I added the checks and return statements, removed the redundancy and I am still getting the same error. – Multitut Sep 13 '18 at 13:21
  • Clear out all of the code and just return null from the trigger. See if you still get error. – James Poag Sep 13 '18 at 13:22
  • Thanks. I reduced my trigger to only return null and the same error persists. I will update my question with this info. – Multitut Sep 13 '18 at 13:27
  • What I believe is happening is that you are watching a node that is too large to trigger on. since you are only interested in the `serie` sub-value, perhaps you can rewrite your trigger to watch just that node: `functions.database.ref('forms/{pushId}/serie').onCreate` – James Poag Sep 13 '18 at 13:29
  • 1
    That seems to be the problem, it worked when I narrowed down the ref as you suggested. I downloaded the whole forms node to a json file and it is 3mb... it doesn't sound like a big deal to me. – Multitut Sep 14 '18 at 19:48

0 Answers0