Continue Discussion 13 replies
February 2022

Filipe_Cunha

I’m have tested your code, but the rollback does not work.

          return await strapi.db.connection.transaction(async (transacting) => {
              // Find the user
              try{
                const fromUser = await strapi.query('api::local.local').create({ data:{id:444 }}, null, { transacting });
                const toUser = await strapi.query('api::local.local').create({ data:{id:999 }}, null, { transacting });

  
              // respond with the receipt (don't forget to sanitize our output!)
              return "worked"
              }
              catch(e){
                return e
              }
          });

here, the id 999 already exists in the database, and it returns duplicated key error, however, the id 444 is inserted before this error and not removed when the transaction fails.

I also tried the following approach:

      async transaction2(ctx){
        const transacting = await strapi.db.connection.transaction();
        try {
          const fromUser = await strapi.query('api::local.local').create({ data:{id:444}}, null, { transacting });
          const toUser = await strapi.query('api::local.local').create({ data:{id:999}}, null, { transacting });
          await transacting.commit();
          return "Deu"
      } catch (err) {
          await transacting.rollback();
          console.log("ROLLBACK")
          return err
      }
      } 

The result is the same. When I call the rollback function, the first query is not reverted.
Any solution for this?

1 reply
February 2022

Filipe_Cunha

well… forum is dead I guess

April 2022

Filipe_Cunha

Bump…
Guess I’m not using STRAPI, first question I ask cant even get an answer xD
sad

2 replies
April 2022 ▶ Filipe_Cunha

aveprik

Try discord, although your experience will most likely be similar.
The question to answer ratio here and in discord is pretty sad, yes.

I found better results arrive if you mention people. Specifically Derrik (DMehaffy). He is the most responsive person out of entire company and out of entire forum to be honest. This guy clearly cares but he is just one human being and there are this many questions :slight_smile:

April 2022 ▶ Filipe_Cunha

commentsBot Strapi Official Bot

HI @Filipe_Cunha and sorry for the late reply. We are currently organizing a process to be more responsive and the author has been notified. If you’re stuck, as @aveprik mentioned, Discord is the best place to get help, our Solutions Engineers @DMehaffy, @Richard_Nsama and @bolg55 will do their best to help you out.