Trying to update from Node 14 to 18, I encountered a handful of issues. One issue was described on github with a fix here which worked in my datastore conflict handler. However, inside one of my React Context files there is a handleNetworkStatus function which updates records that were changed while the user was offline and this function doesn't accept the model and I have been unable to find a similar fix or apply that same logic to this area of code. Other functions within the same context file use the exact same object type in their DataStore.save call and have no problems.
Expected behavior
The DataStore.save call succeeds.
Reproduction steps
Starting with a React/Capacitor project which uses AppSync, DynamoDB, Lambdas, and NodeJS 14, update to NodeJS 18 and attempt to update a record which triggers code inside handleNetworkStatus.
Code Snippet
// TodoContext.tsx
// Both Todo.copyOf calls reference the same model in index.d.ts
const updateTodo = async (changed: MutableTodo) => {
...
await DataStore.save( // this one works fine
Todo.copyOf(original, (updated) => {
const keys = Object.keys(updatedTodo).filter(
(k: string) => !DATASTORE_IGNORE_FIELDS.includes(k)
);
for (let i = 0; i < keys.length; i += 1) {
const key = keys[i] as keyof Trial;
if (key !== 'crop') {
updated[key as keyof Trial] = updatedTrial[key];
}
...
function handleNetworkStatus(connected: boolean) {
...
try {
if (newInfo) {
await DataStore.save(
Todo.copyOf(todo, (updated) => { // error occurs here
updated.info = newInfo;
})
// index.d.ts
export declare type Todo = LazyLoading extends LazyLoadingDisabled ? EagerTodo : LazyTodo
export declare const Todo: (new (init: ModelInit<Todo, TodoMetaData>) => Todo) & {
copyOf(source: Todo, mutator: (draft: MutableModel<Todo, TodoMetaData>) => MutableModel<Todo, TodoMetaData> | void): Todo;
}
```
// Put your logs below this line
Updating info details for todo: Test0327.2 failed due to the following error: Error: The source object is not a valid model
at Model.copyOf (datastore.js:523:1)
at TodoContext.tsx:239:1
```
I didn't write this code and those who did have moved on but I have done my best to include enough non-identifiable information about the code and the error.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication, DataStore, Storage, PubSub
Amplify Categories
auth, storage, function, api, hosting
Environment information
Describe the bug
Trying to update from Node 14 to 18, I encountered a handful of issues. One issue was described on github with a fix here which worked in my datastore conflict handler. However, inside one of my React Context files there is a handleNetworkStatus function which updates records that were changed while the user was offline and this function doesn't accept the model and I have been unable to find a similar fix or apply that same logic to this area of code. Other functions within the same context file use the exact same object type in their DataStore.save call and have no problems.
Expected behavior
The DataStore.save call succeeds.
Reproduction steps
Starting with a React/Capacitor project which uses AppSync, DynamoDB, Lambdas, and NodeJS 14, update to NodeJS 18 and attempt to update a record which triggers code inside handleNetworkStatus.
Code Snippet
Log output
aws-exports.js
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
I didn't write this code and those who did have moved on but I have done my best to include enough non-identifiable information about the code and the error.