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

RealmModule definition replaced in the library by definition from the application #7855

Closed
andriy-svirskyy opened this issue Oct 28, 2023 · 3 comments

Comments

@andriy-svirskyy
Copy link

How frequently does the bug occur?

Always

Description

Library contains database tables and class to create the corresponding RealmConfiguration. RealmConfiguration creation:

public final class DatabaseConfiguration {
    //
    // module
    //
    @RealmModule(library = true, allClasses = true)
    private static final class module_t {}


    private static final long SCHEMA = 10;

    private static final module_t module_ = new module_t();
    @Nullable
    private final String location_;
    @NonNull
    private final String name_;

    public DatabaseConfiguration(@NonNull final String input) {
        final File path = new File(input);
        location_ = path.getParent();
        name_ = path.getName();
    }

    @NonNull
    public RealmConfiguration run() {
        final RealmConfiguration.Builder builder = new RealmConfiguration
                .Builder()
                .name(name_)
                .schemaVersion(SCHEMA)
                .deleteRealmIfMigrationNeeded()
                .modules(module_);

        if(null != location_)
            builder.directory(new File(location_));

        return builder.build();
    }
}

Application contains several Realm databases with corresponding classes producing RealmConfiguration, but without @RealmModule definition. With this configuration database configuration from the library contains expected scheme. Schema verified by the following code in the app's Application class immediately Realm initialization (see log A):

Realm.init(context);
Realm.setDefaultConfiguration(new RealmConfiguration.Builder().
        name("local.realm").
        schemaVersion(REALM_SCHEMA).
        deleteRealmIfMigrationNeeded().
        compactOnLaunch(new StorageCompactOnLaunch(Application.class, -1007238489)).
        build());
if(DEBUG) {
    @NonNull final var configuration =
            new uk.co.pintent.easymap.poi.converter.data.DatabaseConfiguration("remote_A.realm").run();
    final var classes = configuration.getRealmObjectClasses();
    log_.debug("remote schema begin");
    for(final var current: classes)
        log_.debug("schema --> " + current);
    log_.debug("remote schema end");
}// if()

I define @RealmModule for any of the app's database configurations without using it:

public final class DatabaseConfiguration {
    @RealmModule(classes = { StorageResponse.class, StorageResultRoot.class, StorageResultSuccess.class, StorageSuggestion.class })
    private static final class module_t {}


    private static final long SCHEMA_VERSION = 1;

    @NonNull
    private final String name_;

    public DatabaseConfiguration(@NonNull final String input) {
        name_ = input;
    }

    @NonNull
    public RealmConfiguration run() {
        return new io.realm.RealmConfiguration.Builder()
                .name(name_)
                .schemaVersion(SCHEMA_VERSION)
                .deleteRealmIfMigrationNeeded()
                .build();
    }
}

After this database schema from the library contains classes defined in the application's @RealmModule, see log B.

This confirms that schema definition in the library effectively gets replaced by schema defined in the application.

Stacktrace & log output

Log A:

10-28 06:03:51.918 D/fddj3839v2sc6zbm4ya2( 2290): 06:03:51.918 [main] DEBUG fddj3839v2sc6zbm4ya2 - remote schema begin
10-28 06:03:51.919 D/fddj3839v2sc6zbm4ya2( 2290): 06:03:51.919 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.poi.converter.data.StoragePOI
10-28 06:03:51.919 D/fddj3839v2sc6zbm4ya2( 2290): 06:03:51.919 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.poi.converter.data.StorageTag
10-28 06:03:51.919 D/fddj3839v2sc6zbm4ya2( 2290): 06:03:51.919 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.poi.converter.data.StorageTagKey
10-28 06:03:51.920 D/fddj3839v2sc6zbm4ya2( 2290): 06:03:51.920 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.poi.converter.data.StorageRoot
10-28 06:03:51.920 D/fddj3839v2sc6zbm4ya2( 2290): 06:03:51.920 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.poi.converter.data.StorageCategory
10-28 06:03:51.921 D/fddj3839v2sc6zbm4ya2( 2290): 06:03:51.921 [main] DEBUG fddj3839v2sc6zbm4ya2 - remote schema end


Log B:

10-28 06:21:37.424 D/fddj3839v2sc6zbm4ya2( 2852): 06:21:37.424 [main] DEBUG fddj3839v2sc6zbm4ya2 - remote schema begin
10-28 06:21:37.424 D/fddj3839v2sc6zbm4ya2( 2852): 06:21:37.424 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.backend.here.task.geocoderautocomplete.StorageResponse
10-28 06:21:37.425 D/fddj3839v2sc6zbm4ya2( 2852): 06:21:37.424 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.backend.here.task.geocoderautocomplete.StorageResultSuccess
10-28 06:21:37.425 D/fddj3839v2sc6zbm4ya2( 2852): 06:21:37.425 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.backend.here.task.geocoderautocomplete.StorageSuggestion
10-28 06:21:37.425 D/fddj3839v2sc6zbm4ya2( 2852): 06:21:37.425 [main] DEBUG fddj3839v2sc6zbm4ya2 - schema --> class uk.co.pintent.easymap.backend.here.task.geocoderautocomplete.StorageResultRoot
10-28 06:21:37.425 D/fddj3839v2sc6zbm4ya2( 2852): 06:21:37.425 [main] DEBUG fddj3839v2sc6zbm4ya2 - remote schema end

Can you reproduce the bug?

Sometimes

Reproduction Steps

Bug is reproduced within the main application only and cannot be reproduced with test application.

Version

io.realm:realm-gradle-plugin:10.16.1

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android API 26

Build environment

Android Studio version: 2022.3.1 Patch 2

Application:

Android Build Tools version: 33.0.2
Gradle version: com.android.tools.build:gradle:7.4.2

Library:

Gradle version: 8.0, plugin 8.1.1

@rorbech
Copy link
Contributor

rorbech commented Nov 20, 2023

Closing as duplicate of internal issue HELP-52312.

@rorbech rorbech closed this as completed Nov 20, 2023
@andriy-svirskyy
Copy link
Author

Hi @rorbech ,

Closing as duplicate of internal issue HELP-52312.
When is it going to be in production please?

@rorbech
Copy link
Contributor

rorbech commented Nov 30, 2023

@andriy-svirskyy This seem to be because the two @RealmModules have the same class name (module_t). Created #7860 with more details of the internals. As a work around you can just use different class names for your @RealmModules.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants