Skip to content

QueryPredicateGroup inside syncExpression filters cause DataStore sync to fail #3125

@tylerjroach

Description

@tylerjroach

Before opening, please confirm:

Language and Async Model

Java

Amplify Categories

DataStore

Gradle script dependencies

N/A

Environment information

N/A

Please include any relevant guides or documentation you're referencing

No response

Describe the bug

QueryPredicateGroup has a bad Gson serializer/deserializer.

This causes data to be improperly stored in the syncExpression column of LastSyncMetadata.

The initial sync may work correctly, but any subsequent sync attempts fail because QueryPredicate isn't properly registered in GsonFactory. The issue is caused by not being able to handle nested query predicates (groups and groups of groups).

Fixes Required:

  1. Clean up the serialization and deserialization for QueryPredicateGroup
  2. Do a 1 time delete of all syncExpressions within LastSyncMetadata that contain groups.
  3. Added a migration_flags table to mark when the invalid entries were deleted (or set by default on database recreation)

Reproduction steps (if applicable)

Add a sync expression like:

DataStoreConfiguration.builder().apply {
    syncExpression(
        Todo::class.java,
        { Todo.NAME.eq("Name").and(Todo.TODO_ID.eq("123")) }
    )
}.build()

Watch initial sync pass, with subsequent sync's fail. Notice missing "_type" fields in serialized model in db

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


Configuration File

No response

GraphQL Schema

// Put your schema below this line

Additional information and screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions