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

[WARN] 18:15.415 DataStore - subscriptionError Connection failed: #12473

Closed
3 tasks done
MeryAmun opened this issue Oct 30, 2023 · 10 comments
Closed
3 tasks done

[WARN] 18:15.415 DataStore - subscriptionError Connection failed: #12473

MeryAmun opened this issue Oct 30, 2023 · 10 comments
Assignees
Labels
DataStore Related to DataStore category

Comments

@MeryAmun
Copy link

MeryAmun commented Oct 30, 2023

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

DataStore, Interactions

Amplify Categories

storage, api, interactions

Environment information

# Put output below this line

System:
    OS: Windows 10 10.0.19045
    CPU: (4) x64 AMD A6-5200 APU with Radeon(TM) HD Graphics
    Memory: 1.43 GB / 7.47 GB
  Binaries:
    Node: 16.17.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 9.2.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (118.0.2088.69)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @aws-amplify/ui-react-native: ^1.2.28 => 1.2.28
    @babel/core: ^7.19.3 => 7.22.17
    @babel/plugin-proposal-export-namespace-from: ^7.18.9 => 7.18.9
    @react-native-async-storage/async-storage: 1.18.2 => 1.18.2
    @react-native-community/netinfo: 9.3.10 => 9.3.10
    HelloWorld:  0.0.1
    amazon-cognito-identity-js: ^6.3.6 => 6.3.6
    amazon-cognito-identity-js/internals:  undefined ()
    aws-amplify: ^5.3.11 => 5.3.11
    core-js: ^3.33.1 => 3.33.1
    expo: ^49.0.3 => 49.0.10
    expo-constants: ~14.4.2 => 14.4.2
    expo-image-picker: ~14.3.2 => 14.3.2
    expo-linking: ~5.0.2 => 5.0.2
    expo-router: 2.0.0 => 2.0.0
    expo-splash-screen: ~0.20.4 => 0.20.5
    expo-status-bar: ~1.6.0 => 1.6.0
    react: 18.2.0 => 18.2.0
    react-dom: 18.2.0 => 18.2.0
    react-native: 0.72.4 => 0.72.4
    react-native-gesture-handler: ~2.12.0 => 2.12.1
    react-native-get-random-values: ~1.9.0 => 1.9.0
    react-native-reanimated: ~3.3.0 => 3.3.0
    react-native-safe-area-context: 4.6.3 => 4.6.3
    react-native-screens: ~3.22.0 => 3.22.1
    react-native-url-polyfill: ^2.0.0 => 2.0.0 (1.3.0)
    react-native-web: ~0.19.6 => 0.19.8
  npmGlobalPackages:
    @aws-amplify/cli: 11.0.3
    @nestjs/cli: 9.1.5
    @sanity/cli: 2.35.0
    create-expo-app: 2.0.4
    create-react-app: 5.0.1
    eas-cli: 4.1.2
    expo-cli: 6.3.10
    firebase-tools: 11.23.1
    firebase: 9.17.1
    npm: 9.2.0
    yarn: 1.22.19

Describe the bug

when I try to fetch the list of users available in the Data store, I get an empty array, despite the fact that I have 3 users currently in the store

Expected behavior

display data from AWS amplify after running Datastore.query(User).then(setUsers)

Reproduction steps

import { useState, useEffect } from "react";
import UserCard from "../src/components/UserCard";
import { Link } from 'expo-router'
import { useAuthenticator } from "@aws-amplify/ui-react-native";
import { DataStore} from "aws-amplify";
import { User } from '../src/models/index'

export default function Page() {
  const [users, setUsers] = useState([])

  useEffect(() => {
   DataStore.query(User).then(setUsers);
  },[])
  console.log('users',users)

Code Snippet

// Put your logs below this line

WARN [WARN] 18:15.415 DataStore - subscriptionError Connection failed: {"errors":[{"message":"Validation error of type FieldUndefined: Field '_version' in type 'User' is undefined @ 'onUpdateUser/_version'"},{"message":"Validation error of type FieldUndefined: Field '_lastChangedAt' in type 'User' is undefined @ 'onUpdateUser/_lastChangedAt'"},{"message":"Validation error of type FieldUndefined: Field '_deleted' in type 'User' is undefined @ 'onUpdateUser/_deleted'"}]}
WARN [WARN] 18:15.471 DataStore {"cause": {"error": {"errors": [Array]}, "provider": {"_config": [Object], "awsRealTimeSocket": [WebSocket], "connectionState": "Connecting", "connectionStateMonitor": [ConnectionStateMonitor], "connectionStateMonitorSubscription": [Subscription], "keepAliveAlertTimeoutId": 470, "keepAliveTimeout": 300000, "keepAliveTimeoutId": 469, "promiseArray": [Array], "reconnectionMonitor": [ReconnectionMonitor], "socketStatus": 1, "subscriptionObserverMap": [Map]}}, "errorType": "Unknown", "localModel": null, "message": "Connection failed: {"errors":[{"message":"Validation error of type FieldUndefined: Field '_version' in type 'User' is undefined @ 'onUpdateUser/_version'"},{"message":"Validation error of type FieldUndefined: Field '_lastChangedAt' in type 'User' is undefined @ 'onUpdateUser/_lastChangedAt'"},{"message":"Validation error of type FieldUndefined: Field '_deleted' in type 'User' is undefined @ 'onUpdateUser/_deleted'"}]}", "model": "User", "operation": "Update", "process": "subscribe", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}
WARN [WARN] 25:13.66 DataStore {"cause": {"data": null, "errors": [[Object], [Object]]}, "errorType": "Unknown", "localModel": null, "message": undefined, "model": "Post", "operation": null, "process": "sync", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}
WARN [WARN] 25:13.608 DataStore {"cause": {"data": null, "errors": [[Object], [Object]]}, "errorType": "Unknown", "localModel": null, "message": undefined, "model": "User", "operation": null, "process": "sync", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@MeryAmun MeryAmun added the pending-triage Issue is pending triage label Oct 30, 2023
@nadetastic nadetastic added the DataStore Related to DataStore category label Oct 31, 2023
@chrisbonifacio chrisbonifacio self-assigned this Oct 31, 2023
@chrisbonifacio
Copy link
Contributor

chrisbonifacio commented Oct 31, 2023

Hi @MeryAmun 👋 thank you for raising this issue.

{"errors":[{"message":"Validation error of type FieldUndefined: Field '_version' in type 'User' is undefined @ 'onUpdateUser/_version'"},{"message":"Validation error of type FieldUndefined: Field '_lastChangedAt' in type 'User' is undefined @ 'onUpdateUser/_lastChangedAt'"},{"message":"Validation error of type FieldUndefined: Field '_deleted' in type 'User' is undefined @ 'onUpdateUser/_deleted'"}]}

Based on the error message, it seems that Conflict Detection may not be enabled. The _version, _lastChangedAt, and _deleted fields are automatically added to models if Conflict Detection is enabled on your GraphQL API.

You can check by running amplify update api > GraphQL > Do you get an option to enable or disable conflict detection?

If it's already enabled, then try running amplify push to make sure the changes are deployed and then amplify codegen models to re-generate the DataStore models locally.

Also, as a side note, I'd like to mention that unless you have a specific requirement for offline capabilities in your application, we recommend using the API library to perform GraphQL requests with the best balance of performance and reliability.

@cwomack cwomack added investigating This issue is being investigated pending-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage labels Oct 31, 2023
@MeryAmun
Copy link
Author

Hi @chrisbonifacio Thank you for taking out your time to respond to my query.I checked and it was disabled. can tou please give me a run down on how to get it eneabled and the best resolution strategy. Thank you again. I had abandoned a previous project because of this same problem and I was already thinking of quitting AWS Amplify.

@chrisbonifacio
Copy link
Contributor

chrisbonifacio commented Nov 1, 2023

Hi @MeryAmun. Happy to help!
To enable it the CLI flow is amplify update > GraphQL > Enable conflict detection > amplify push
When the deployment is complete, run amplify codegen models to make sure DataStore's schema is up to date.

Auto Merge should be fine as a default for most use cases. For more info on how the strategies work:
https://docs.aws.amazon.com/appsync/latest/devguide/conflict-detection-and-sync.html#conflict-detection-and-resolution

@chrisbonifacio
Copy link
Contributor

@MeryAmun let me know if those steps fixed the original issue for you!

@Abdullah47744
Copy link

@chrisbonifacio I followed you but didn't work i have the same issue
i can't read data from aws with the same error
WARN [WARN] 41:42.35 DataStore {"cause": {"locations": null, "message": "Cannot return null for non-nullable type: 'Int' within parent 'Restaurant' (/syncRestaurants/items[0]/_version)", "path": ["syncRestaurants", "items", 0, "_version"]}, "errorType": "BadRecord", "localModel": null, "message": "Cannot return null for non-nullable type: 'Int' within parent 'Restaurant' (/syncRestaurants/items[0]/_version)", "model": "Restaurant", "operation": "syncRestaurants", "process": "sync", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}
WARN [WARN] 41:42.56 DataStore {"cause": {"locations": null, "message": "Cannot return null for non-nullable type: 'AWSTimestamp' within parent 'Restaurant' (/syncRestaurants/items[0]/_lastChangedAt)", "path": ["syncRestaurants", "items", 0, "_lastChangedAt"]}, "errorType": "BadRecord", "localModel": null, "message": "Cannot return null for non-nullable type: 'AWSTimestamp' within parent 'Restaurant' (/syncRestaurants/items[0]/_lastChangedAt)", "model": "Restaurant", "operation": "syncRestaurants", "process": "sync", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}

@chrisbonifacio
Copy link
Contributor

Hi @MeryAmun it sounds like DataStore is trying to sync down some records that might've been created before it was enabled, so they do not have those fields, causing the error.

You will have to either delete those records in DynamoDB (if in a dev environment) or backfill them with values for those fields. _version can be set to 1, _deleted can be false, and _lastChangedAt can be set to an arbitrary date.

@cwomack
Copy link
Contributor

cwomack commented Nov 22, 2023

@MeryAmun and @Abdullah47744, can you let us know if following the instructions above from @chrisbonifacio help resolve the issue? Thanks.

@cwomack cwomack added pending-response Issue is pending response from the issue requestor and removed pending-response Issue is pending response from the issue requestor labels Nov 22, 2023
@saf3961227
Copy link

@MeryAmun let me know if those steps fixed the original issue for you!

Hey @MeryAmun I followed your instructions and it worked! Thanks!!

@Abdullah47744
Copy link

Abdullah47744 commented Dec 4, 2023 via email

@chrisbonifacio chrisbonifacio removed investigating This issue is being investigated pending-response Issue is pending response from the issue requestor labels Dec 4, 2023
@rupakg
Copy link

rupakg commented Jan 6, 2024

@chrisbonifacio thank you for your explanation of the solution.

For others, if you did your Amplify model creation via Amplify Studio, you can resolve this issue by:

  • delete all the records you created for your models
  • delete all your models
  • manage the conflict resolution and other flags by going to GraphQL API settings -> Conflict resolution & offline capabilities -> Enabled.
  • save and deploy
  • create your models
  • create data for your models (optional)
  • amplify pull --appId <your_app_id> --envName staging - this should sync your state, update the api and models, and also generate code for your models.

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataStore Related to DataStore category
Projects
None yet
Development

No branches or pull requests

7 participants