Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction failed to execute #1394

Open
cpgb85 opened this issue Sep 24, 2021 · 12 comments
Open

Transaction failed to execute #1394

cpgb85 opened this issue Sep 24, 2021 · 12 comments

Comments

@cpgb85
Copy link

cpgb85 commented Sep 24, 2021

In older version of dexie I used, i was able to use this alone to update a row:

await this.$root.db.orders.where('id').equals(id).modify(order);

Now it throws that it will not execute for me. What changed between older versions and the newest version?

@dfahlander
Copy link
Collaborator

It should still work the same. Can you create a repro?

@cpgb85
Copy link
Author

cpgb85 commented Oct 7, 2021

Not really sure how to do that. This seems to happen when I call Dexie from vue routes.

`async update(){

  this.error = '';
  this.success = '';
  let hashString = '';
  for(let field in this.region.acf){
    hashString += `${field}${this.region.acf[field]}`;
  }
  let hash = `${this.$store.state.application_password}${sha256(hashString)}`;
  let req = await fetch(`${this.$store.state.api}/regions/${this.region.ID}`, {
    method:'POST',
    body:JSON.stringify({...this.region.acf, ...{hash:hash}})
  });
  let res = await req.json();
  console.log(res)
  if(res.hasOwnProperty('error')){
    this.error = res.error;
  }
  if(res.hasOwnProperty('success')){
    this.success = res.success;
  }
  
  await this.$store.state.db.regions.where('id').equals(this.region.id).modify({acf:this.region.acf});

}`

@dfahlander
Copy link
Collaborator

dfahlander commented Oct 7, 2021

Could it be that your update() function is called from within another transaction? The update function does non-indexeddb work (fetch()) so the IDB transaction will be lost. Try if it works better if you surround the dexie call with Dexie.ignoreTransaction()

await Dexie.ignoreTransaction(()=>
  this.$store.state.db.regions.where('id').equals(this.region.id).modify({acf:this.region.acf})
);

If you were on dexie 1.x before, it did not survive scopes across native async calls, so the call to dexie might have worked because neither dexie or indexedDB knew about the actual ongoing transaction from the caller. Dexie >= 2.0 will keep the active transaction zone alive between await calls but IndexedDB still loose the transaction when calling fetch() or other non-IDB work.

If this is the case, please revisit the calling code also. Do you intend to call update() within the same transaction of the caller, or doesn't it matter. If so, do also consider changing the calling code to call update() outside its transaction. Note that a callback to dexie's each() will also be running within an implicit transaction, causing the same behavior as if you'd explicitely surrounded the call to each() with a transaction scope.

@cpgb85
Copy link
Author

cpgb85 commented Oct 11, 2021

I'm using Dexie 3.0.3. I'm still encountering the same issue with this code:

await Dexie.ignoreTransaction(()=> this.$store.state.db.compressors.where('id').equals(this.compressor.id).modify({acf:this.compressor.acf}) );

@cpgb85
Copy link
Author

cpgb85 commented Oct 11, 2021

On the mounted method, I retrieve the compressor i need:

async mounted(){ this.compressor = _.first(await this.$store.state.db.compressors.where('id').equals(parseFloat(this.$route.params.compressor_id)).toArray()); this.ready = true; console.log(this.compressor.acf.sump) },
After that, my form calls the update method:

<Form :validation-schema="schema" @submit="update" v-slot="{ errors }" autocomplete="off">

Once submitted, I call the update method i created:

async update(){ await this.$store.state.db.compressors.where('id').equals(this.compressor.id).modify({acf:this.compressor.acf}) }

I don't understand what else I can do to make this work. It used to work in the past i feel and randomly it stopped working.

@dfahlander
Copy link
Collaborator

What error do you get? code of your update() function seems pretty straight forward, given that this.$store.state.db is a Dexie instance, "compressors" is in your schema and declared as having primary key "id", and that this.compressor.acf is a clonable type. Can you share the result of doing JSON.stringify(this.compressor.acf) in the moment of calling modify()?

@cpgb85
Copy link
Author

cpgb85 commented Oct 11, 2021

Sure. ACF is a column inside of the compressors table. It stores a JSON object.

{"4000":475,"6000":475,"8000":475,"sump":0,"500_or_less":0,"control_parts_2x_acp":0,"control_parts_3x_acp":0,"control_parts_4x_acp":0}

No matter what I attempt, any column or table it just continues to tell me the transaction has finished error. I'm able to perform all other methods properly without error. These update or modify methods are the only issues I encounter.

@cpgb85
Copy link
Author

cpgb85 commented Oct 11, 2021

image

@cpgb85
Copy link
Author

cpgb85 commented Oct 11, 2021

image

@dfahlander
Copy link
Collaborator

Ok. Trying some last things here (brainstorming):

  • Check if your device is close to the maximum quota for storage. You can do it programmatically using StorageManager.
  • What browser are you on? Or is it Electron? Chromium has a similar bug that we are currently trying a workaround in PR A workaround for issue 613 #1398 (see issue 613 comment on how you could apply it)
  • Is the update function called massively at the same time? Browsers may have some reasonable limit on how many simultanous transactions can be flying at the same time.
  • What happens if you downgrade dexie? Is the problem only occuring in 3.0.3?
  • Could you try upgrade dexie to see if there's a difference? npm i dexie@next (or use the version of the A workaround for issue 613 #1398 pull request)

@cpgb85
Copy link
Author

cpgb85 commented Oct 12, 2021

So I downgraded my version to 2.0.4. I get an error as usual, but i can make it work by saving the "acf" object as a string instead of JSON instead. This does not work in 3.0.3.

@cpgb85
Copy link
Author

cpgb85 commented Dec 7, 2021

I'm still encountering the same issues randomly. Looking at your suggestions, do you think using Brave (chromium based) could have anything to do with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants