Support Topics Documentation Slack YouTube Blog

Transaction returning false success

Using Swift SDK 6.0
Copied example from Docs

Is transaction successful - false

Here is the example code used
No objects getting created

@objcMembers class Person: NSObject {
      var name: String?
      var age: Int = 0
  }
func test(){

    let unitOfWork = UnitOfWork()

    let person = Person()
    person.name = "Joe"
    person.age = 25

    let addPersonResult = unitOfWork.create(objectToSave: person)
    
    unitOfWork.execute(responseHandler: { (UnitOfWorkResult) in
        print("Is transaction successful - \(UnitOfWorkResult.isSuccess)")
        print(UnitOfWorkResult.results)
    }) { (Fault) in
        
    }
}

Hello Robert,

If transaction execution failes you receive the error message that describes the issue:

UnitOfWorkResult.error?.message

Could you please provide that error?

Regards,
Olha

Thanks,

All tables and columns must be present in the database before a transaction is executed.

Had some optionals that hadn’t been generated yet.

When using transactions, the schema must be predefined as the database doesn’t allow schema changes during a transaction.

Im running into the issue again, but this time trying to create a relation with a BackendlessUser Parent object
Optional(“Table ‘Optional BackendlessUser’ does not exists. Please make sure to configure your schema first. All tables and columns must be present in the database before a transaction is executed.”).

Could you please show how you reference the parent object in the code? Any sample code which would give us the context of the error will be very helpful.

Tried to create a test app to demonstrate it, but without the springboard plan it looks like transactions is disabled.

      let uow = UnitOfWork()
    _ = uow.create(objectToSave: BECompany.sharedInstance)
   // let user = uow.update(objectToSave: Backendless.shared.userService.currentUser)  // This Crashes the app
     let myUser  = uow.create(objectToSave: getBEUserProperty())
    _ = uow.setRelation(parentObject: Backendless.shared.userService.currentUser, columnName: kUserPropKey, childrenResult: myUser)
     uow.execute(responseHandler: { result in
         print("Is transaction successful - \(result.isSuccess)")
        print(result.error?.message)

     }, errorHandler: { fault in
         print("Error: \(fault.message ?? "")")
     })

I am somewhat confused and need your help. From the earlier message I understood that you get an error when you run a transaction. The sample code you posted has a commented out line This crashes the app. Is this a separate issue or they are related? (“app crashing” and “error from the transaction”)

A few more questions:

  • Does the transaction error happen with the code you posted? (where there is a commented line)?
  • What Backendless plan is the app on? I didn’t quite understand how you can run the transaction but also said “Tried to create a test app to demonstrate it, but without the springboard plan it looks like transactions is disabled.”

The test app I have in the console is free plan, trial expired.
This app is still on cloud 99 trial.

The commented line is a separate issue, sorry I should have removed it from the reply.

It looks like the backend is looking for a Table Called BackendlessUser instead of Users during a set relation transaction. (It may be the same issue calling update that’s commented out)

Thank you for clarifying, Robert. We will look into it and investigate the problem.

Regards,
Mark

The internal ticket BKNDLSS-22249 is created for this issue.

Regards,
Olha

Issue is found and the fix will be available very soon.

Regards,
Olha

1 Like

Hello Robert,
New version of Swift-SDK 6.0.1 is now available. Could you please check?
Here is a code I’ve tested and it should work now:

Backendless.shared.userService.login(identity: "test@test.com", password: "111", responseHandler: { loggedInUser in
                
    let uow = UnitOfWork()

    Backendless.shared.userService.currentUser?.name = "New Name"
    let _ = uow.update(objectToSave: Backendless.shared.userService.currentUser!)
                
    let addressesResult = uow.find(tableName: "Address", queryBuilder: nil)

    let _ = uow.setRelation(parentObject: Backendless.shared.userService.currentUser!, columnName: "addresses", childrenResult: addressesResult)
                
    uow.execute(responseHandler: { result in
        print("Is transaction successful - \(result.isSuccess)")
        if !result.isSuccess {
            print("Transaction failed: \(result.error?.message ?? "")")
        }
    }, errorHandler: { fault in
        print("Error: \(fault.message ?? "")")
    })
}, errorHandler: { fault in
    print("Login error: \(fault.message ?? "")")
})

Regards,
Olha

Sorry Olha, I think I opened a can of worms here. Looks like “update” crashes when a custom object is attached to the BackendlessUser

Im getting another error on the original issue

Unable to perform ‘SET_RELATION’ operation due to argument incompatibility. The operation references a result from another ‘CREATE’ operation. The specified result cannot be obtained from this operation (list of objectIds).

here is example code to cause a crash

@objcMembers
class Person : NSObject {
var name : String = “Jim”
var objectId : String?
}

        let uow = UnitOfWork()
        let per = Person()
        Backendless.shared.userService.currentUser!.properties["person"] = per
         let myUser  = uow.create(objectToSave: per)

        let _ = uow.update(objectToSave: Backendless.shared.userService.currentUser!)
                                          
        uow.execute(responseHandler: { result in
            print("Is transaction successful - \(result.isSuccess)")
            if !result.isSuccess {
                print("Transaction failed: \(result.error?.message ?? "")")
            }
        }, errorHandler: { fault in
            print("Error: \(fault.message ?? "")")
        })

Hello Robert,
I can reproduce this issue and I’ll start fixing it as soon as possible.

Regards,
Olha

The new version 6.0.1.1 of Swift-SDK is released.
Please check now.

Regards,
Olha