Search code examples
javascriptindexeddbdexie

Dexie: SubTransactionError


I am getting this error when running a transaction in Dexie:

name: SubTransactionError message: table _ not included in parent transaction

this only happens after I run this code:

DeleteApiToken.then (() => {
            CacheController.Invalidate();
            DataControllerCreator.Blocked++;
            Render();
        });
        Api.Call(this.ApiCall,this.Data,() => {DataControllerCreator.Blocked--;},{ResetCacheState: this.ResetCacheState});
    };

and the DeleteApiToken function looks like this.

function DeleteApiToken() {
            return DB.transaction('rw', DB.MySelf, () => {
                DB.MySelf.delete('ApiToken');
            }).catch(function (E) {
                console.log(E);
                return false;

            })
        }

The Render function then causes the app to re-render and more transactions are run, but they all throw the previously mentioned error. If the DeleteApiToken is not called they do not.

If you can see an error with my code that would be great, otherwise just a simple explanation of why the SubTransactionError can be thrown would be enough. Thanks!


Solution

  • It seems unlikely that this code alone would cause the error. The error indicates that there is a table named underscore. It's that so? If not, I would suspect that you have unintentionally changed the 'name' property of the DB.MySelf table to underscore.

    Another question is whether DB is used in other functions such as CacheController.Invalidate()? How does the code look there if so?

    Explanation of the error: SubTransactionError can only happen when a transaction is started from within an ongoing transaction and the new transaction tries to include a table that was not included in the ongoing transaction. Example:

    db.transaction ('rw', 'friends', ()=>{
        db.transaction ('rw', 'pets', ()=>{
            // SubTransactionError: Table 'pets' not included in parent transaction. 
        });
    });