-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to Core 12.5.1 #967
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Minor comments ... but haven't evaluated the questions for @cmelchior, so will leave him to do the final approval.
@@ -1033,10 +1042,14 @@ actual object RealmInterop { | |||
): RealmQueryPointer { | |||
memScoped { | |||
val count = args.size | |||
val cArgs = allocArray<realm_value_t>(count) | |||
val cArgs = allocArray<realm_query_arg_t>(count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a code block that are used a number of times. Should probably be abstracted into a method and reused instead of copying it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've extracted it to a separate function and added a comment to clarify the usage of realm_query_arg_t
as it is a bit quirky.
return memScope { | ||
args.mapIndexed { i, arg -> | ||
realmc.valueArray_setitem(cArgs, i, managedRealmValue(arg)) | ||
realm_query_arg_t().apply { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as for native ... we should probably put this in a separate method
…g test cases for anonymous login without reusing existing user
CHANGELOG.md
Outdated
@@ -21,7 +22,7 @@ | |||
* Minimum Android SDK: 16. | |||
|
|||
### Internal | |||
* None. | |||
* Updated to Realm Core 12.5.0, commit 4b0a203b202b7a91caf2a387e17e5623d7b37c4a. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
beforeCallback.onBeforeReset(beforeDb) | ||
true | ||
} catch (e: Throwable) { | ||
false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we log the exception here? It seems to be swallowed otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this returns false
then the execution follows through onError
instead, which is the intended behaviour we sought after reporting realm/realm-core#5564 to Yavor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we shouldn't throw it here, but this error is hidden so people wouldn't know they have buggy code. Could we at least do println(e.toStrint)
here??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, I missed you meant log the error. Hm, we can do it easily for native but JVM is a bit more convoluted...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to address JVM regardless, since exceptions are leaking. I think if we can use Kotlin println...it will work correctly on both JVM and Android...It isn't ideal, but should be sufficient until we can come up with something better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Native is not an issue at all, I can call println
with the exception message. For JVM I will add some functions to api_helpers
to extract the exception message from JNI and then do the whole JNI ceremony thing to call System.out.println
. I'm not sure we can call Kotlin's println
since it's a top level function which might be tricky to find by JNI.
afterCallback.onAfterReset(beforeDb, afterDb, didRecover) | ||
true | ||
} catch (e: Throwable) { | ||
false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
@@ -27,6 +27,7 @@ import io.realm.kotlin.internal.interop.sync.AuthProvider | |||
*/ | |||
public enum class AuthenticationProvider(id: AuthProvider) { | |||
ANONYMOUS(AuthProvider.RLM_AUTH_PROVIDER_ANONYMOUS), | |||
ANONYMOUS_NO_REUSE(AuthProvider.RLM_AUTH_PROVIDER_ANONYMOUS_NO_REUSE), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit weird that this is its own auth provider, but I. guess we are just exposing the underlying data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is Core's new enum, even though it adds no value having it 🤷 . In fact, its addition caused .NET to have a crash after they updated their Core to 12.5.0: realm/realm-dotnet#2987 so I'd rather add it to avoid problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like .NET still only have one auth provider. Is there a way for us to do something similar? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, it's because they don't have an enum watchdog test but we do 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant, is there a way for us to only have one auth provider for this in the public API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so. It would be a matter of changing the testing setup to handle both true
and false
values while testing ANONYMOUS(AuthProvider.RLM_AUTH_PROVIDER_ANONYMOUS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After another discussion, I think there is an edge case we are not accounting for on the JVM
@@ -664,19 +664,25 @@ before_client_reset(void* userdata, realm_t* before_realm) { | |||
auto before_pointer = wrap_pointer(env, reinterpret_cast<jlong>(before_realm), false); | |||
env->CallVoidMethod(static_cast<jobject>(userdata), java_before_callback_function, before_pointer); | |||
jni_check_exception(env); | |||
|
|||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't any changes to code on the JVM side, which means that if the callback throws on the JVM, then jni_check_exception(env);
will throw an exception instead of returning false.
Do we have any unit tests of us manually throwing an exception in BeforeClientReset
? I
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, onBefore
here https://github.com/realm/realm-kotlin/pull/967/files#diff-4496cd276f4c265c4a34d2d6835c8a1e290376d9d2d30380bb4dc60ac49a94ebR547
and onAfter
here https://github.com/realm/realm-kotlin/pull/967/files#diff-4496cd276f4c265c4a34d2d6835c8a1e290376d9d2d30380bb4dc60ac49a94ebR599
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I debugged it when I wrote this for automatic client reset in a separate branch and looks like jni_check_exception
does the catching and forwards the error appropriately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After carefully inspecting the execution it seems it does work because the error is intercepted by the error handler instead, then we detect the error itself has isClientResetRequested
so it's routed through the client reset handler. I will change it so that it doesn't take that path and stays within the client reset flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funnily enough the before/after callbacks in the C-API throw an exception too:
if (!callback(userdata.get(), &r1)) { // if we return false it will be caught here
throw CallbackFailed();
}
so the execution stays the same regardless. I will return false
for consistency with native though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception catch could be done in the cinterop with a lambda.
…er, removed "anonymous no reuse" provider from the public API
# Conflicts: # packages/cinterop/src/darwin/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. I added some comments about exception catching on the client reset callbacks.
afterCallback.onAfterReset(beforeDb, afterDb, didRecover) | ||
true | ||
} catch (e: Throwable) { | ||
println(e.message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use our internal logger so this message could be captured by a custom logger?
Maybe the exception catch could happen in a higher layer, even would be a common logic for all platforms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The internal logger isn't available in cinterop unfortunately. I'm not sure there is good way to get this to work right now, but it is something we should track and hopefully fix when we look into combining our modules.
I'm merging this after discussing options for the logger, having reached the conclusion that may be worth waiting until a potential package refactor. |
Fixes #867
Updated to Core 12.5.1 and fixed the following breaking changes
realm_query_arg_t
instead of arealm_value_t
- see Query parser: IN realm-core#4266 for more details.realm_convert_with_config
now receives a boolean that triggers copying over all objects present in the realm specified by the provided configuration, though we default it tofalse
to avoid copying things - thoughs @cmelchior?onBefore
andonAfter
client reset callbacks now return a boolean to allow routing errors throughonError
in Kotlin Native. As a consequence of thisSyncClientResetIntegrationJVMTests.kt
was no longer needed and was removed.realm_sync_wait_for_completion_func_t
.TODO:
reuseExisting = false