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

DataStore error when deleting optional @hasOne relationship when empty #10685

Closed
3 tasks done
mmoulton opened this issue Nov 18, 2022 · 3 comments
Closed
3 tasks done
Assignees
Labels
bug Something isn't working DataStore Related to DataStore category

Comments

@mmoulton
Copy link

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

DataStore

Amplify Categories

No response

Environment information

# Put output below this line
  System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 274.03 MB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.18.2 - ~/.nvm/versions/node/v14.18.2/bin/node
    Yarn: 1.22.1 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v14.18.2/bin/npm
  Browsers:
    Chrome: 107.0.5304.110
    Firefox: 94.0.2
    Safari: 16.0
  npmPackages:
    aws-amplify: ^4.3.43 => 4.3.43 
    typescript: ^4.5.5 => 4.7.4 (3.9.10, 4.4.4)
  npmGlobalPackages:
    @aws-amplify/cli: 8.5.1

Describe the bug

DataStore is throwing Failed to execute 'get' on 'IDBIndex': The parameter is not a valid key. when attempting to delete a model that contains a @hasOne relationship that is optional and that relationship is not set on the model being removed.

The original error starts here:

.get(this.canonicalKeyPath(values))

However I traced the root of the issue to this block here:

const value = model[targetName];
values = [value];

It seems that when the relationship is not defined value will be null, making values equal [null].

This is a problem for the break condition defined here:

Since values being [null] will not satisfy this condition, as it should.

Expected behavior

To be able to delete models with @hasOne relationships.

Reproduction steps

  1. Define a model with a @hasOne relationship to another model where the relationship is not required.
  2. Create a now instance of the 'parent' model.
  3. Attempt to delete the 'parent' model.

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


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

@tannerabread tannerabread added DataStore Related to DataStore category pending-triage Issue is pending triage labels Nov 18, 2022
@chrisbonifacio chrisbonifacio added the to-be-reproduced Used in order for Amplify to reproduce said issue label Nov 18, 2022
@chrisbonifacio chrisbonifacio self-assigned this Nov 18, 2022
@dpilch
Copy link
Contributor

dpilch commented Nov 18, 2022

I was able to reproduce. Investigating a fix.

@dpilch dpilch removed the to-be-reproduced Used in order for Amplify to reproduce said issue label Nov 18, 2022
@dpilch dpilch added bug Something isn't working and removed pending-triage Issue is pending triage labels Nov 19, 2022
@dpilch
Copy link
Contributor

dpilch commented Nov 19, 2022

A patch was released in V5. Please upgrade to aws-amplify@5.0.3 or downgrade to aws-amplify@4.3.37. The patch will be backported to V4 in the next few days.

@dpilch dpilch assigned dpilch and unassigned chrisbonifacio Nov 21, 2022
@chrisbonifacio
Copy link
Contributor

@mmoulton closing this as fixed. Please upgrade and let us know if this is resolved on your end afterwards. Thank you!

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 Related to DataStore category
Projects
None yet
Development

No branches or pull requests

4 participants