Updating or deleting fauna collection records doesn't work on deployed site

I have integrated faunadb into my app. I built very simple CRUD behavior into my function. Create and retrieve work well - I’m able to create a new document, and retrieve documents. But when attempting to delete, or update a document, while the code doesn’t fail, the results are not recorded in the collection.

This only occurs in the deployed app. When the app runs on my local machine (using netlify-lambda) records in the collection change.

Here’s the rough code:

async update(id, data = {}) {

    let result = null;

    if(!id) {

      console.error('record id missing');

      throw 'record id missing';

    }

    try {

      await this.client.query(q.Update(q.Ref(q.Collection(this.COLLECTION), id), {data}));

    }

    catch(err) {

      console.error(err);

    }

    finally {

      return result;

    }

  }

  async delete(id) {

    if(!id) {

      console.error('record id missing');

      throw 'record id missing';

    }

    try {

      let result = await this.client.query(q.Delete(q.Ref(q.Collection(this.COLLECTION), id)));

      console.log(result);

    }

    catch(err) {

      console.error(err);

    }

    finally {

      return;

    }

  }

Again, this code works locally 100% of the time, and doesn’t on Netlify 100% of the time.

Is this a network issue? A fauna issue? How should I go about troubleshooting it.

Since you have some error handling in there, I guess you don’t see anything useful in the logs? Could you try also logging that you’re trying a connection (say, between try { and let result ...), so we can be sure the try blocks are running at all?

I’m grasping at straws a bit since I would have suggested to test in netlify-lambda serve and you say that works already…

I’ve done some more research, and found out Fauna is not the blame - it seems like DELETE and PUT methods do not reach the function. That leads to these 2 operations not being called.

I re-posted this issue: https://community.netlify.com/t/cant-call-lambda-function-with-delete-or-put-methods/6246

I have no idea why those methods are blocked in production.

I’ve tested a bare function that just console.logs the http method and I was successfully able to invoke the function using both a DELETE and PUT method. I don’t think the issue is specific to how we are proxying to that function. From this, I can say that those methods aren’t being blocked.

As fool suggested, you could try adding console.logs to your function to give you better visibility on what’s going on.

Hi Dennis,
Can confirm - created a brand new function from scratch, and managed to fetch it with method DELETE. I guess I have something else wrong in my code.
Although it might be some sort of “magic”, as I’ve replicated the function code to a new file almost verbatim, and I can call the new one, but not the old one…

At any rate, this is not a Netlify issue, but my code. We can close this issue.

Thanks for all your help and time!

Thanks for the update! Let me know how it goes.