montagejs / montage

Montage is an elegant, open source HTML5 framework maintained by Montage Studio that rivals native SDKs, yet is easier to learn. It offers modular components, two-way data binding, and much more. Join us on irc.freenode.net#montage. Sign up for our beta to build Montage applications in the cloud.
http://montagestudio.com/montagejs
Other
1.51k stars 214 forks source link

DataService. _performAndDeleteOfflineOperation incorrectly null checks for offlineService and schema #2019

Open tejaede opened 4 years ago

tejaede commented 4 years ago

The logic of the following section of DataService. _performAndDeleteOfflineOperation is logically inconsistent.

            if (this.offlineService) {
                tableSchema = this.offlineService.schema[operationType];
                foreignKeys = tableSchema.foreignKeys;
            }

            if (!foreignKeys) {
                foreignKeys = tableSchema._computedForeignKeys ||
                    (tableSchema._computedForeignKeys = Object.keys(operation.changes));
            }

https://github.com/montagejs/montage/blob/master/data/service/data-service.js#L2395-L2404

If this.offlineService is undefined, tableSchema and foreignKeys will not be set in the first conditional. That forces the code to throw in the second condition. !foreignKeys is true so the code enters the block and tableSchema is necessarily undefined.

tejaede commented 4 years ago

@marchant

I am not sure what the correct solution is so this issue is designed to track the discussion. This is not a blocker for us.