forcedotcom / SalesforceMobileSDK-ReactNative

BSD 3-Clause "New" or "Revised" License
48 stars 55 forks source link

Application Crashed on Alter soup. | UNIQUE constraint failed: TABLE_19.id #373

Closed mahipalsingh-syt closed 2 months ago

mahipalsingh-syt commented 2 months ago

When we reSync Application it got crashed and unable to launch application.

configList.forEach((soupDetails: SoupType.SoupDetails, index: number) => {
          mobilesync.getSyncStatus(
            {},
            soupDetails.syncName[0],
            (sync: any) => {
              if (sync === null) {
                smartstore.registerSoup(
                  false,
                  soupDetails.soupName,
                  soupDetails.indexes,
                  () => {
                    // keeping empty as we are only registering
                    if (index === configList.length - 1) {
                      resolve(true);
                    }
                  },
                  (error) => {
                    reject(error);
                  }
                );
              } else {
                smartstore.alterSoup(
                  {},
                  soupDetails.soupName,
                  soupDetails.indexes,
                  true,
                  () => {
                    resolve(true);
                  },
                  () => {
                    resolve(true);
                  }
                );
              }
            },
            (error: any) => {
              reject(error);
            }
          );
        })
Result: UNIQUE constraint failed: TABLE_19.id
At line 1:
INSERT INTO TABLE_19 (id,created,lastModified,soup,TABLE_19_1,TABLE_19_0,TABLE_19_2) SELECT id,created,lastModified,soup,TABLE_19_1,TABLE_19_0,TABLE_19_2 FROM TABLE_19_old

Platform: iOS "sdkDependencies": { "SalesforceMobileSDK-Android": "https://github.com/forcedotcom/SalesforceMobileSDK-Android.git#v10.0.0", "SalesforceMobileSDK-iOS": "https://github.com/forcedotcom/SalesforceMobileSDK-iOS.git#v10.0.0" }, "react-native": "0.67.5", "react-native-force": "git+https://github.com/forcedotcom/SalesforceMobileSDK-ReactNative.git#v10.0.0"

wmathurin commented 2 months ago

Hello @mahipalsingh-syt I see you opened the same issue here as well. Since it looks like a SmartStore problem rather than a React Native one, I will close this issue.

wmathurin commented 2 months ago

It looks like you are firing multiple calls to registerSoup or alterSoup in parallel. You should rewrite your code to do the register/alter soup for each soup details once the previous one completed. So have a method that take the index and call itself with index + 1 in the success callback.