Dev mode enabled for Realm App Service, but Schema not generated by app

using realm package 1.1.0, and when I run my flutter app, it no longer generates a schema (after removing a collection from the Atlas app service, terminating the sync, and restarting in Dev Mode).

Launching lib/main.dart on iPhone 14 Pro Max in debug mode...
Xcode build done.                                            9.6s
[VERBOSE-2:FlutterDarwinContextMetalImpeller.mm(35)] Using the Impeller rendering backend.
Connecting to VM Service at ws://127.0.0.1:51396/Gs4bnXxaf68=/ws
flutter: 2023-06-05T09:38:47.939773: [INFO] Realm: Realm sync client ([realm-core-13.12.0])
flutter: 2023-06-05T09:38:47.949838: [INFO] Realm: Platform: iOS Darwin 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000 x86_64
flutter: 2023-06-05T09:38:47.951404: [INFO] Realm: Connection[1]: Session[1]: Binding '/Users/joshuawhitehouse/Library/Developer/CoreSimulator/Devices/AAA219F3-7055-4AA6-A6E9-BEF251DB60F8/data/Containers/Data/Application/56E93498-9D98-412E-8D3F-912E3B451867/Documents/mongodb-realm/stellaevents-iplin/63d7d4954db30956f6ae2080/default.realm' to ''
flutter: 2023-06-05T09:38:47.951590: [INFO] Realm: Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, client reset = false
flutter: 2023-06-05T09:38:47.951823: [INFO] Realm: Connection[1]: Connecting to 'wss://ws.realm.mongodb.com:443/api/client/v2.0/app/stellaevents-iplin/realm-sync'
flutter: 2023-06-05T09:38:47.952130: [INFO] Realm: Connected to endpoint '34.227.4.145:443' (from '192.168.1.10:51402')
flutter: 2023-06-05T09:38:47.955877: [INFO] Realm: Connection[1]: Connected to app services with request id: "647de56764136a45a9a47cd6"
flutter: 2023-06-05T09:38:49.191796: [INFO] Realm: Connection[1]: Session[1]: Received: ERROR "Invalid query (IDENT, QUERY): failed to parse query: query contains table not in schema: "StellaEvent"" (error_code=226, try_again=false, error_action=ApplicationBug)
flutter: 2023-06-05T09:38:49.198855: [ERROR] Realm: SyncSessionError message: Invalid query (IDENT, QUERY): failed to parse query: query contains table not in schema: "StellaXXX" Logs: https://realm.mongodb.com/groups/62a258e7fd33f65229a1f35b/apps/62f155c93587e6e83c5e67c4/logs?co_id=647de56764136a45a9a47cd6 category: SyncErrorCategory.session code: SyncSessionErrorCode.badQuery isFatal: true
flutter: 2023-06-05T09:38:49.210881: [INFO] Realm: Connection[1]: Disconnected

My flutter dev environment…

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.2, on macOS 13.4 22F66 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.78.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Rolled back to the flutter realm 1.0.3 version, terminated sync deleted the app service schema for the collection, restarted the device sync with Dev Mode enabled, and the schema for this collection was generated by the app with no issues. Seems to be a 1.1.0 issue

Try rolling forward again. I don’t think this is an issue with 1.1.0, but the

… terminated sync deleted the app service schema for the collection, restarted the device sync with Dev Mode enabled

fixed it for you.

Notice the error. It is complaining about StellaXXX

flutter: 2023-06-05T09:38:49.198855: [ERROR] Realm: SyncSessionError message: Invalid query (IDENT, QUERY): failed to parse query: query contains table not in schema: "StellaXXX" Logs: https://realm.mongodb.com/groups/62a258e7fd33f65229a1f35b/apps/62f155c93587e6e83c5e67c4/logs?co_id=647de56764136a45a9a47cd6 category: SyncErrorCategory.session code: SyncSessionErrorCode.badQuery isFatal: true

This error only occurred in the 1.1.0 release of the realm flutter package. This is how I encountered it…

  1. in the App Services section of the MongoDB Atlas web page, terminated sync from the Device Sync section.
  2. deleted the schema for this collection under the Schema section
  3. restarted the Device Sync with Development Mode enabled
  4. ran the flutter app

after performing this, in 1.0.3 realm flutter package the schema for this collection is rebuilt when I start the app. But in 1.1.0, I get the query contains table not in schema: "StellaXXX" exception, and there is no schema rebuilt for the collection like there is in 1.0.3., it’s only occurring with the 1.1.0 release of the realm flutter package.

Did you try rolling forward again? It is not totally clear to me.

The error link is from a iOS device using v1.0.3:

SDK:
Dart v1.0.3
Framework:
Flutter v2.19.6 (stable) (Tue Mar 28 13:41:04 2023 +0000) on “ios_x64”

https://realm.mongodb.com/groups/62a258e7fd33f65229a1f35b/apps/62f155c93587e6e83c5e67c4/logs?co_id=647de56764136a45a9a47cd6

I rolled forward to 1.1.0, and it’s working fine, after the schema for the collection was recreated using the 1.0.3 package.

1.1.0 fails when there is no schema for the collection present in the app services. 1.0.3 creates the schema (I have Development Mode switched on in the Device Sync for this app service, but it looks like 1.1.0 fails to.

To recreate -

  1. Terminate Sync
  2. delete the schema for the collection under the Schema section of App Services in Atlas.
  3. with Developement Mode on, enable sync again
  4. run the flutter app that connects to this app service

at this point,

1.0.3 - successfully generates the missing schema for the collection
1.1.0 - reports the table not in schema, no schema for the collection is generated (like it is in 1.0.3)

I hope this clears up any confusion, will be glad to answer more questions. Again, downgrading to 1.0.3 and running the app generated the missing schema, and upgrading to us 1.1.0 after using 1.0.3 (and successfully generating the missing schema) runs fine.

We will look into this tomorrow. One of the differences between v1.0.3 and v1.1.0 is the version of realm-core that they use.

I will get back when I know more.

It seems the subscription queries are uploaded prior to the schema, possibly due to changes regarding automatic migration from partition based to flexible sync.

Has absolutely no relevance for Flutter, as we never supported the former, but we still use the same version of realm-core.

We will investigate further.

Hi @Josh_Whitehouse,
We managed to reproduce this issue using the steps that you’ve reported. So, thank you for reporting the issue.
The only workaround that we found for now was deleting also the local realm file before running the app. Then the schema is generated on the App service. You can use this workaround, if it is acceptable for you to delete the data, until we find better solution.
We will investigate further.

@Josh_Whitehouse,
After the investigation we recall that we don’t force re-creating the server schema, once the realm exists locally and has subscriptions added. And this is not from the new version. I suspect you have deleted the realm file when you have downgraded to 1.0.3.
You can add some code to clear the subscriptions just before closing the app or realm

  realm.subscriptions.update((mutableSubscriptions) {
    mutableSubscriptions.clear();
  });

and to add the subscriptions again once the app is started. On this way you will force schema re-generation on the server next time you open the app. You can do this for developing purpose. But it is not recommended for the production.

To elaborate. We are still working on this. The client should receive a client reset, when this situation happens.

1 Like

ok, for development purposes, I’ll clear the subscriptions when closing the realm. They were being cleared after opening the realm, but now I’ve added clearing to to closing the realm as well for dev purposes.

2 Likes