Object is not an instance of a valid model
See original GitHub issueBefore opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React Native
Amplify APIs
DataStore
Amplify Categories
api
Environment information
System:
OS: macOS 11.6
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 1.87 GB / 16.00 GB
Shell: 5.0.11 - /usr/local/bin/bash
Binaries:
Node: 14.12.0 - /usr/local/bin/node
Yarn: 1.22.5 - /usr/local/bin/yarn
npm: 7.24.1 - /usr/local/bin/npm
Browsers:
Chrome: 94.0.4606.61
Safari: 15.0
npmPackages:
@aws-amplify/datastore: ^3.4.7 => 3.4.7
@aws-amplify/datastore-storage-adapter: ^1.1.7 => 1.1.7
@babel/core: ^7.9.0 => 7.15.5 (7.9.0)
@expo/vector-icons: ^12.0.0 => 12.0.5
@react-native-async-storage/async-storage: ^1.15.8 => 1.15.8
@react-native-community/datetimepicker: 3.5.2 => 3.5.2
@react-native-community/eslint-config: 1.1.0
@react-native-community/eslint-plugin: 1.0.0
@react-native-community/netinfo: ^6.0.2 => 6.0.2
@react-navigation/bottom-tabs: ^6.0.5 => 6.0.7
@react-navigation/native: ^6.0.2 => 6.0.4
@react-navigation/native-stack: ^6.1.0 => 6.2.2
@stripe/stripe-react-native: 0.1.4 => 0.1.4
@types/react: ~16.9.35 => 16.9.56 (17.0.24)
@types/react-native: ~0.63.2 => 0.63.53 (0.65.1)
HelloWorld: 0.0.1
amazon-cognito-identity-js: ^5.2.0 => 5.2.0
aws-amplify: ^4.3.1 => 4.3.1
aws-amplify-react-native: ^5.0.3 => 5.0.3
babel-plugin-inline-view-configs: 0.0.5
expo: ~42.0.1 => 42.0.4
expo-asset: ~8.3.2 => 8.3.3
expo-constants: ~11.0.1 => 11.0.1 (11.0.2)
expo-font: ~9.2.1 => 9.2.1
expo-linking: ~2.3.1 => 2.3.1
expo-splash-screen: ~0.11.2 => 0.11.4
expo-status-bar: ~1.0.4 => 1.0.4
expo-web-browser: ~9.2.0 => 9.2.0
hermes-inspector-msggen: 1.0.0
ini: ^1.3.5 => 1.3.8
inquirer: ^6.5.1 => 6.5.2 (3.3.0)
jest-expo: ~41.0.0-beta.0 => 41.0.0
moment: ^2.29.1 => 2.29.1
react: 16.13.1 => 16.13.1
react-animated: 0.1.0
react-dom: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz => 0.63.2
react-native-codegen: 0.0.2
react-native-config: ^1.4.4 => 1.4.4
react-native-datepicker: ^1.7.2 => 1.7.2
react-native-elements: ^3.4.2 => 3.4.2
react-native-gesture-handler: ~1.10.2 => 1.10.3
react-native-maps: 0.28.0 => 0.28.0
react-native-paper: ^4.9.2 => 4.9.2
react-native-reanimated: ~2.2.0 => 2.2.2
react-native-safe-area-context: 3.2.0 => 3.2.0
react-native-screens: ~3.4.0 => 3.4.0
react-native-sqlite-storage: ^6.0.1 => 6.0.1
react-native-web: ~0.13.12 => 0.13.18
typescript: ~4.0.0 => 4.0.8
npmGlobalPackages:
@aws-amplify/cli: 6.1.1
amplify-cli: 1.0.0
expo-cli: 4.12.0
gatsby-cli: 2.10.2
npm: 7.24.1
sharp-cli: 1.15.0
Describe the bug
When I write to datastore I got this error:
[ERROR] 43:57.200 DataStore - Object is not an instance of a valid model, Object {
"model": Event {
"description": "Lorem ipsum dolor sit amet",
"name": "Lorem ipsum dolor sit amet",
},
}
Expected behavior
I expect that it will write to the datastore
Reproduction steps
I have followed these instructions https://docs.amplify.aws/lib/datastore/getting-started/q/platform/js/
I have this schema:
type Event {
id: ID!
name: String!
description: String
}
And this in my app.js
import { StatusBar } from "expo-status-bar";
import React, { useEffect } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import useCachedResources from "./hooks/useCachedResources";
import useColorScheme from "./hooks/useColorScheme";
import Navigation from "./navigation";
import { DataStore, Analytics, Auth } from "aws-amplify";
//import { DataStore } from "@aws-amplify/datastore";
import { SQLiteAdapter } from "@aws-amplify/datastore-storage-adapter";
import { Event } from "./src/models/index";
import { withAuthenticator } from "aws-amplify-react-native";
import Amplify from "aws-amplify";
import awsconfig from "./src/aws-exports";
Analytics.disable();
Amplify.configure(awsconfig);
window.LOG_LEVEL = "DEBUG";
DataStore.configure();
function App() {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
useEffect(() => {
const test = async () => {
await DataStore.save(
new Event({
name: "Lorem ipsum dolor sit amet",
description: "Lorem ipsum dolor sit amet",
})
);
};
test();
});
if (!isLoadingComplete) {
return null;
} else {
return (
<SafeAreaProvider>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</SafeAreaProvider>
);
}
}
export default withAuthenticator(App);
Code Snippet
No response
Log output
// Put your logs below this line
[ERROR] 13:02.614 DataStore - Object is not an instance of a valid model, Object {
"model": Event {
"description": "Lorem ipsum dolor sit amet",
"name": "Lorem ipsum dolor sit amet",
},
}
at node_modules/@aws-amplify/core/lib-esm/Logger/ConsoleLogger.js:138:12 in prototype._log
at http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:195593:21 in <unknown>
at node_modules/@aws-amplify/datastore/lib-esm/datastore/datastore.js:688:34 in __generator$argument_1
at http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:227538:26 in step
at node_modules/@aws-sdk/client-cognito-identity/node_modules/@aws-crypto/sha256-js/node_modules/tslib/tslib.js:122:34 in <anonymous>
at node_modules/@aws-sdk/client-cognito-identity/node_modules/@aws-crypto/sha256-js/node_modules/tslib/tslib.js:112:44 in fulfilled
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
iphone 13
Mobile Operating System
ios 15.0
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
React Amplify/Datastore- cannot get delete record to delete
I was passing an array of objects. DataStore.delete(toDelete) would work with the 2nd example but not the first since that was an object....
Read more >Object Model
Note that the property values do not necessarily need to be model instances to be considered valid: only the definition of the associated...
Read more >Understanding the "Objects are not valid as a react child" Error ...
The error "Objects are not valid as a React child" is rather common and the solution is to manipulate the object so that...
Read more >Inheritance and the prototype chain - JavaScript | MDN
We say that new Box(1) is an instance created from the Box constructor function. Box.prototype is not much different from the boxPrototype ...
Read more >Model instance reference — Django 4.1.4 documentation
Note that instantiating a model in no way touches your database; for that, ... CharField(max_length=100) objects = BookManager() book ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After pushing everything I can’t reproduce it anymore
Yes indeed and an auth user is needed