Skip to content

Datastore observer queryPredicate evaluated incorrectly. #1525

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

Closed
1 task done
PS-MS opened this issue Oct 7, 2021 · 1 comment
Closed
1 task done

Datastore observer queryPredicate evaluated incorrectly. #1525

PS-MS opened this issue Oct 7, 2021 · 1 comment
Labels
bug Something isn't working datastore DataStore category/plugins

Comments

@PS-MS
Copy link

PS-MS commented Oct 7, 2021

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

DataStore

Gradle script dependencies

// Put output below this line
    def amplify_version = "1.28.0"

    implementation 'com.amplifyframework:core-kotlin:0.12.0'
    implementation "com.amplifyframework:aws-storage-s3:$amplify_version"
    implementation "com.amplifyframework:aws-auth-cognito:$amplify_version"
    implementation "com.amplifyframework:aws-api:$amplify_version"
    implementation "com.amplifyframework:aws-datastore:$amplify_version"

Environment information

# Put output below this line


Please include any relevant guides or documentation you're referencing

AWSDataStorePlugin.java

Describe the bug

I have noticed an issue with AWSDataStorePlugin::observe when using a QueryPredicate where the changed item is not being returned to the observer due to the changed item being evaluated incorrectly

Reproduction steps (if applicable)

No response

Code Snippet

when using a predicate such as Inspection.ORG_ID.eq(organization) the observer is not returning the result of any changes that do match the predicate, I have had a look into the observe method and believe the reason is the evaluate parameter

selectionCriteria.evaluate(itemChange)

Removing the query predicate does return the result and I have used the evaluate method to see what the evaluation result should be:

changedInspection -> 
DataStoreItemChange evaluation: Inspection.ORG_ID.eq(organization).evaluate(changedInspection) // returns false
Item evaluation: Inspection.ORG_ID.eq(organization).evaluate(changedInspection.item()) // return true

This is the AWSDataStorePlugin method being used:

    @Override
    public <T extends Model> void observe(
            @NonNull Class<T> itemClass,
            @NonNull QueryPredicate selectionCriteria,
            @NonNull Consumer<Cancelable> onObservationStarted,
            @NonNull Consumer<DataStoreItemChange<T>> onDataStoreItemChange,
            @NonNull Consumer<DataStoreException> onObservationFailure,
            @NonNull Action onObservationCompleted) {
        start(() -> onObservationStarted.accept(sqliteStorageAdapter.observe(
            itemChange -> {
                try {
                    if (itemChange.modelSchema().getName().equals(itemClass.getSimpleName()) &&
                            selectionCriteria.evaluate(itemChange)) {
                        @SuppressWarnings("unchecked") // itemClass() was just inspected above. This is safe.
                        StorageItemChange<T> typedChange = (StorageItemChange<T>) itemChange;
                        onDataStoreItemChange.accept(ItemChangeMapper.map(typedChange));
                    }
                } catch (DataStoreException dataStoreException) {
                    onObservationFailure.accept(dataStoreException);
                }
            },
            onObservationFailure,
            onObservationCompleted
        )), onObservationFailure);
    }

Log output

No response

amplifyconfiguration.json

No response

GraphQL Schema

// Put your schema below this line

Additional information and screenshots

No response

@sktimalsina sktimalsina added bug Something isn't working datastore DataStore category/plugins labels Oct 8, 2021
@eeatonaws
Copy link
Contributor

A fix for this issue has been released as part of Amplify Android 1.28.2.

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

No branches or pull requests

3 participants