Skip to content
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

Invalid Column key when using child properties with the BETWEEN keyword. #7935

Closed
derrickgw opened this issue Jul 15, 2024 · 5 comments · Fixed by #7965 · May be fixed by realm/realm-dart#1770
Closed

Invalid Column key when using child properties with the BETWEEN keyword. #7935

derrickgw opened this issue Jul 15, 2024 · 5 comments · Fixed by #7965 · May be fixed by realm/realm-dart#1770
Assignees

Comments

@derrickgw
Copy link

What happened?

I got Unhandled Exception: RealmException: Invalid column key. Error code: 3009. when trying to use the between key for a DateTime field.

Repro steps

Using a child property with the BETWEEN keyword doesn't work. Using < or > operators works with child properties without issue.

The exception is thrown regardless of whether the query should return anything.

Version

3.19

What Atlas Services are you using?

Local Database only

What type of application is this?

Flutter Application

Client OS and version

Android & Linux

Code snippets

This is sufficient code to expose the issue.

import 'package:realm/realm.dart';

import "model.dart";

void main() {
  final config = Configuration.inMemory([Parent.schema, Child.schema]);
  final realm = Realm(config);
  final stop = DateTime.now();
  final start = stop.subtract(const Duration(days: 1));

  print("The naive way:");
  realm.query<Parent>(r"$0 <= child.timestamp && child.timestamp <= $1", [start, stop]);
  print("The between way:");
  realm.query<Parent>(r"child.timestamp between {$0, $1}", [start, stop]);
}
import 'package:realm/realm.dart';

part "model.realm.dart";

@RealmModel()
class $Child {
  late DateTime timestamp;
}

@RealmModel()
class $Parent {
  $Child? child;
}

Stacktrace of the exception/crash you're getting

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RealmException: Invalid column key. Error code: 3009.
#0      _raiseLastError.<anonymous closure> (package:realm_dart/src/handles/native/error_handling.dart:59:9)
realm/realm-dart#1      using (package:ffi/src/arena.dart:124:31)
realm/realm-dart#2      _raiseLastError (package:realm_dart/src/handles/native/error_handling.dart:48:3)
realm/realm-dart#3      BoolEx.raiseLastErrorIfFalse (package:realm_dart/src/handles/native/error_handling.dart:25:7)
realm/realm-dart#4      ResultsHandle.count.<anonymous closure> (package:realm_dart/src/handles/native/results_handle.dart:74:55)
realm/realm-dart#5      using (package:ffi/src/arena.dart:124:31)
realm/realm-dart#6      ResultsHandle.count (package:realm_dart/src/handles/native/results_handle.dart:72:12)
realm/realm-dart#7      RealmResults.length (package:realm_dart/src/results.dart:115:28)
realm/realm-dart#8      new RealmResults._ (package:realm_dart/src/results.dart:30:12)
realm/realm-dart#9      RealmResultsInternal.create (package:realm_dart/src/results.dart:298:7)
realm/realm-dart#10     Realm.query (package:realm_dart/src/realm_class.dart:435:33)
realm/realm-dart#11     main (package:realm_test/main.dart:14:9)
realm/realm-dart#12     _runMain.<anonymous closure> (dart:ui/hooks.dart:301:23)
realm/realm-dart#13     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
realm/realm-dart#14     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Relevant log output

No response

Copy link

sync-by-unito bot commented Jul 15, 2024

➤ PM Bot commented:

Jira ticket: RDART-1071

@nielsenko
Copy link
Contributor

@derrickgw I can confirm this regression. Could you try using realm 3.1.0 as a work-around?

@nielsenko nielsenko self-assigned this Jul 31, 2024
@nielsenko nielsenko transferred this issue from realm/realm-dart Jul 31, 2024
Copy link

sync-by-unito bot commented Jul 31, 2024

➤ PM Bot commented:

Jira ticket: RCORE-2221

@nielsenko
Copy link
Contributor

This regression was introduced between realm-core v14.9.0 and v14.10.3.

Timestamp are not required, the same issue can be provoked with ints.

import 'package:realm_dart/realm.dart';
import 'package:realm_common/realm_common.dart';

part 'issue1749.realm.dart';

@RealmModel()
class $Child {
  late int number;
}

@RealmModel()
class $Parent {
  $Child? child;
}

void main() {
  final realm = Realm(Configuration.inMemory([Parent.schema, Child.schema]));
  realm.write(() {
    realm.add(Parent(child: Child(1)));
  });

  realm.query<Child>(r"number BETWEEN {$0, $1}", [0, 2]).firstOrNull; // <-- this works
  realm.query<Parent>(r"child.number BETWEEN {$0, $1}", [0, 2]).firstOrNull; // <-- this fails

  Realm.shutdown();
}

@nielsenko
Copy link
Contributor

nielsenko commented Jul 31, 2024

I haven't bisected it, but I suspect

to be the culprit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants