mk-5 / gdx-fireapp

libGDX Firebase API
Apache License 2.0
65 stars 21 forks source link

[Android Database] Transaction always fails if you don't first set a value that run #21

Closed Corrob closed 5 years ago

Corrob commented 5 years ago

Describe the bug My transaction always fails if I don't first set a value in the same run. The value can exist in the database, but if I don't set it that same execution, I get the following crash:

java.lang.RuntimeException: The database value at given path was not be able to commit
        at pl.mk5.gdx.fireapp.promises.FuturePromise.doFail(FuturePromise.java:206)
        at pl.mk5.gdx.fireapp.android.database.TransactionHandler.onComplete(TransactionHandler.java:82)
        at com.google.android.gms.internal.firebase_database.zzcq.run(Unknown Source)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

To Reproduce

database.inReference("test").transaction(
        String.class,
        new Function<String, String>() {
          @Override
          public String apply(String other) {
            return other;
          }
        });

If I add

database.inReference("test").setValue("test");

right before the transaction, then it works. However, this defeats the purpose of using the transaction.

Expected behavior The transaction should succeed.

Platform (please check one of the following):

Smartphone (please complete the following information only if platform is Android or iOS):

mk-5 commented 5 years ago

thanks for the report, I'll look at this and come back to you with some feedback

PandlaS commented 5 years ago

Having the same issue: Getting the message, when trying to run a transaction without setting the database values first.

java.lang.RuntimeException: The database value at given path was not be able to commit

mk-5 commented 5 years ago

Try the new 2.1.1 version - I hope that it fixed now :) The problem was because of aborting transaction when no initial value provided

PandlaS commented 5 years ago

Boom ! Just tried v 2.1.1 and it worked like a charm. Thanks, mk-5. I was eagerly waiting for this fix.

mk-5 commented 5 years ago

No problem :)

Corrob commented 5 years ago

Works for me too. Thanks!

PandlaS commented 5 years ago

I am having some issues with ios-moe (it works perfectly for android). Can somebody check of ios-moe and let me know whether it's working ?

Thanks,

Log:

Terminating app due to uncaught exception 'java.lang.RuntimeException', reason: 'java.lang.RuntimeException: The database value at given path was not be able to commit at pl.mk5.gdx.fireapp.promises.FuturePromise.doFail(FuturePromise.java:206) at pl.mk5.gdx.fireapp.promises.FuturePromise.doFail(FuturePromise.java:218) at pl.mk5.gdx.fireapp.ios.database.QueryRunTransaction$TransactionCompleteBlock.call_runTransactionBlockAndCompletionBlock_1(QueryRunTransaction.java:118) at apple.uikit.c.UIKit.UIApplicationMain(Native Method) at com.mygdx.game.IOSMoeLauncher.main(IOSMoeLauncher.java:24) Caused by: java.lang.Exception: The database value at given path was not be able to commit ... 3 more ' First throw call stack: ( 0 CoreFoundation 0x00000000130961bb __exceptionPreprocess + 331 1 libobjc.A.dylib 0x000000001263c735 objc_exception_throw + 48 2 MOE 0x00000000103adf05 _Z29hasObjCRuntimeBeenInitializedv + 0 3 MOE 0x00000000103b4dd4 _Z24nativeToJavaBlockHandlerP7ffi_cifPvPS1S1 + 1299 4 MOE 0x00000000103ba629 ffi_closure_unix64_inner + 487 5 MOE 0x00000000103b9bb2 ffi_closure_unix64 + 72 6 libdispatch.dylib 0x00000000134db4e1 _dispatch_call_block_and_release + 12 7 libdispatch.dylib 0x00000000134dc54b _dispatch_client_callout + 8 8 libdispatch.dylib 0x00000000134e8380 _dispatch_main_queue_callback_4CF + 1290 9 CoreFoundation 0x0000000012ffb3e9 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 10 CoreFoundation 0x0000000012ff5a76 __CFRunLoopRun + 2342 11 CoreFoundation 0x0000000012ff4e11 CFRunLoopRunSpecific + 625 12 GraphicsServices 0x0000000014bbc1dd GSEventRunModal + 62 13 UIKitCore 0x0000000019ac481d UIApplicationMain + 140 14 MOE 0x00000000103b9a0d ffi_call_unix64 + 85 15 ??? 0x00007ffee802bbc0 0x0 + 140732790913984 ) libc++abi.dylib: terminating with uncaught exception of type ObjCException

mk-5 commented 5 years ago

it's weird okay, I will check that at the beginning of the next week

mk-5 commented 5 years ago

@PandlaS what type of value you try to modify within that transaction? The problem is caused because firebase has returned the message: "not committed" - it means that value wasn't committed for some reason. Maybe something is wrong with java->ios type mapping, but I need to know some more details about the type :)

PandlaS commented 5 years ago

@mk-5 : It's Long type (basically a userId). It seems to be working on Android (same code, no change) but when I run ios-moe, it starts giving that error.

mk-5 commented 5 years ago

@PandlaS please check the new 2.1.2 version - there was a problem with "default" value. Transaction result may not be null, so for example, when type should be String - empty string should be provided instead of null, and that caused the problem. I hope it is gone now; please check it :)