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

Query missing one record and invalid field assignment during read operation #550

Closed
lberbey opened this issue Jul 29, 2023 · 9 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@lberbey
Copy link

lberbey commented Jul 29, 2023

Hi guys,

First of all, sorry for my english (I'm french).

I have two issues on the same project :

  • Invalid return on query : I'm missing one record
  • Invalid field assignment during read operation

Sorry if I'm wrong. Your product is really good and quite easy to use. I'm really happy with it.
I tried to understand sub classes process to fix this but guys, I'm just a simple developer and all the work on ByteArray, Buffer... is far to complex for me 👼 .

Basic info:

  • ObjectBox version: 2.1.0
  • Flutter/Dart SDK:
Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f468f3366c (2 weeks ago) • 2023-07-12 15:19:05 -0700
Engine • revision cdbeda788a
Tools • Dart 3.0.6 • DevTools 2.23.1
  • Reproducible: always
  • Build OS: Windows 10 22H2
  • Deployment device or OS: Android 12 SKQ1.211006.001
  • flutter pub deps --no-dev
Dart SDK 3.0.6
Flutter SDK 3.10.6
objectbox_issue 0.1.0
|-- flutter 0.0.0
|   |-- characters 1.3.0
|   |-- collection 1.17.1
|   |-- js 0.6.7
|   |   '-- meta...
|   |-- material_color_utilities 0.2.0
|   |-- meta 1.9.1
|   |-- sky_engine 0.0.99
|   '-- vector_math 2.1.4
|-- objectbox 2.1.0
|   |-- ffi 2.0.2
|   |-- flat_buffers 2.0.5
|   |-- path 1.8.3
|   |-- collection...
|   '-- meta...
|-- objectbox_flutter_libs 2.1.0
|   |-- path_provider 2.0.15
|   |   |-- path_provider_android 2.0.27
|   |   |   |-- flutter...
|   |   |   '-- path_provider_platform_interface...
|   |   |-- path_provider_foundation 2.2.4
|   |   |   |-- flutter...
|   |   |   '-- path_provider_platform_interface...
|   |   |-- path_provider_linux 2.1.11
|   |   |   |-- xdg_directories 1.0.1
|   |   |   |   |-- meta...
|   |   |   |   '-- path...
|   |   |   |-- ffi...
|   |   |   |-- flutter...
|   |   |   |-- path...
|   |   |   '-- path_provider_platform_interface...
|   |   |-- path_provider_platform_interface 2.0.6
|   |   |   |-- platform 3.1.0
|   |   |   |-- plugin_platform_interface 2.1.5
|   |   |   |   '-- meta...
|   |   |   '-- flutter...
|   |   |-- path_provider_windows 2.1.7
|   |   |   |-- win32 5.0.6
|   |   |   |   '-- ffi...
|   |   |   |-- ffi...
|   |   |   |-- flutter...
|   |   |   |-- path...
|   |   |   '-- path_provider_platform_interface...
|   |   '-- flutter...
|   '-- objectbox...
'-- uuid 3.0.7
    '-- crypto 3.0.3
        '-- typed_data 1.3.2
            '-- collection...
  • flutter doctor -v
[√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [version 10.0.19045.3086], locale fr-FR)
    • Flutter version 3.10.6 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (2 weeks ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\AndroidSDK
    • Platform android-33-ext4, build-tools 33.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.24)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.33328.57
    • Windows 10 SDK version 10.0.20348.0

[√] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)

[√] VS Code, 64-bit edition (version 1.80.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.68.0

[√] Connected device (4 available)
    • M2002J9G (mobile) • 1eabc81d • android-arm64  • Android 12 (API 31)
    • Windows (desktop) • windows  • windows-x64    • Microsoft Windows [version 10.0.19045.3086]
    • Chrome (web)      • chrome   • web-javascript • Google Chrome 115.0.5790.110
    • Edge (web)        • edge     • web-javascript • Microsoft Edge 115.0.1901.188

[√] Network resources
    • All expected network resources are available.

• No issues found!

Steps to reproduce

  1. Load the project from here
  2. Add some breakpoints
main.dart l.187
main.dart l.191
main.dart l.194
objectbox.g.dart l.465
objectbox.g.dart l.469
  1. Execute the project (all breakpoints will be traversed during main.dart execution)

Expected behavior

  1. On main.dart l.191 recipes list should be equal to recipes list on main.dart l.187 like it worked for shops list just above
  2. On main.dart l.194 days[0] should contains 1 item in lunchMenu and 2 in dinnerMenu properties

Code

  • objectbox.g.dart l.465 : value seems available before dbLunchMenu assignment
    objectbox - objectFromFB - before dbLunchMenu
  • objectbox.g.dart l.469 : value is unavailable after dbLunchMenu assignment
    objectbox - objectFromFB - after dbLunchMenu

Additional context

  • I find one workaround for the field assignment during read operation : replace properties lunchMenu and dinnerMenu by menu and dbLunchMenu and dbDinnerMenu by dbMenu but I'm not shure why is it working 😭.

Thanks for your time 🍻 .

@lberbey lberbey added the bug Something isn't working label Jul 29, 2023
@greenrobot-team
Copy link
Member

Thanks for reporting, I could verify your project fails as expected.

Things I should look into:

  • using oneOf conditions with unique String properties (although it appears to work on Shop it doesn't on Recipe)
  • storing an object with two string list properties, it appears only the first is stored?

@greenrobot-team greenrobot-team self-assigned this Jul 31, 2023
@lberbey
Copy link
Author

lberbey commented Jul 31, 2023

Hi,

Thanks for answering that fast.

For your second point, I believe the issue is on read and not on write (or maybe on both...). As you can see in my first capture (original post), I've added the assignation of dbLunchMenu and dbDinnerMenu to WATCH view. Values of the two lists seems to be accessible before the assignation of dbLunchMenu.

I've tried adding a new property List<String> dbZZZ which is read and loaded between dbLunchMenu and dbDinnerMenu. Same results and maybe worst : Both dbZZZ and dbDinnerMenu aren't assigned.

objectbox - objectFromFB - after dbLunchMenu + new dbZZZ property

I tried to switch properties assignment order and it seems to do something : with the order dbZZZ, dbDinnerMenu, dbLunchMenu and dbZZZ equal to ['test'], dbDinnerMenu is also set. Even with dbZZZ equals to [db.generateString(300), db.generateString(700)] it worked.

@greenrobot-team
Copy link
Member

I could isolate the issue: the problem is that as part of setting some properties a database query is executed. This query will run while an object is getting read. This will cause wrong values to be read.

In your code look at the RecipeIngredient.fromDB factory. Removing the database queries there fixes your reported issues.

I still need to investigate if this is something that should work or should throw an error.

@lberbey
Copy link
Author

lberbey commented Aug 7, 2023

Thank you for the work. I understand why I wasn't able to reproduce it only with String.

Correct me if I'm wrong : If I had create all the missing objects (Section, RecipeIngredient...) with the proper ToOne/ToMany relations it would be ok. My issue is all about having one or many read operations during another one.

For my own good, I hope you will improve the tool but I would understand if you don't. I guess it's a lot of work and the community doesn't really need it, otherwise it would have been brought up sooner.

@greenrobot-team greenrobot-team added this to the 2.2.0 milestone Aug 8, 2023
@greenrobot-team
Copy link
Member

greenrobot-team commented Aug 8, 2023

We have released version 2.2.0 which should resolve this issue. Please update using flutter pub upgrade (or dart pub upgrade for Dart Native projects).

@lberbey
Copy link
Author

lberbey commented Aug 8, 2023

Thanks you for the update. Does the new version fix both issues (query and read operation) ?

I've updated my sandbox project as requested and recipes = db.getManyByUuid(... on main.dart l.187 stills returns me 1 object. For the other issue I can confirm that days[0] is now filled with the appropriate values.

@greenrobot-team
Copy link
Member

Thanks! I just verified and this is true. The issue only appears when running a query as part of constructing an object and then querying for those objects.

The query then will only return one object, regardless of how many objects are in the box.

I need to have another look at this.

@greenrobot-team greenrobot-team modified the milestones: 2.2.0, 2.2.1 Aug 22, 2023
@greenrobot-team
Copy link
Member

greenrobot-team commented Aug 22, 2023

We have released version 2.2.1 which I verified resolves this issue with the example project you have given. Please update using flutter pub upgrade (or dart pub upgrade for Dart Native projects).

Thanks again!

@lberbey
Copy link
Author

lberbey commented Aug 26, 2023

Many thanks for your work and time. Everything is fine !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants