question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model can't delete when rangeKey is createdAt

See original GitHub issue

Summary:

When call Model.delete or model.delete, it happens error and can’t delete.

Code sample:

Schema

schema: {
    id: { type: String, hashKey: true },
    createdAt: {
      rangeKey: true,
    },
    schemaOptions: {
        timestamps: true,
    },
}

General

Error happens when call

Model.delete({id:'aaaa',createdAt: 1553137260667})

or

cosnt model = await Model.get({id:'aaaa',createdAt:1553137260667})
model.delete()

Current output and behavior:

TypeError: Cannot read property 'updateTimestamps' of undefined
    at Attribute.toDynamo (/node_modules/dynamoose/dist/Attribute.js:390:30)
    at NewModel.Model.delete (/node_modules/dynamoose/dist/Model.js:1007:65)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)

Maybe, in Attribute.js

Attribute.prototype.toDynamo = async function (val, noSet, model, options) {
...
 if (isTimestamp && options.updateTimestamps === false) {
        runSet = false;
    }
    if (isExpires && options.updateExpires === true) {
        val = await this.default();
        runSet = true;
    }

this will change as below?

Attribute.prototype.toDynamo = async function (val, noSet, model, options) {
...
 if (isTimestamp && options && options.updateTimestamps === false) {
        runSet = false;
    }
    if (isExpires && options && options.updateExpires === true) {
        val = await this.default();
        runSet = true;
    }

Environment:

Node.js version (node -v): 8.10 Dynamoose version: 1.7.2

Dynamoose Plugins:

  • Yes, I believe that one or multiple 3rd party Dynamoose plugins are effecting this issue
  • No, I believe this issue is independent of any 3rd party Dynamoose plugins I’m using
  • Unknown, I’m unsure if Dynamoose plugins are effecting this issue
  • I am not using any Dynamoose plugins

Other information (if applicable):

Type (select 1):

  • Bug report
  • Feature suggestion
  • Question
  • Other suggestion
  • Something not listed here

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn’t been raised or answered before
  • I have tested the code provided and am confident it doesn’t work as intended
  • I have ensured that all of my plugins that I’m using with Dynamoose are listed above
  • I have filled out all fields above
  • I am running the latest version of Dynamoose

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kaoskeyacommented, Jul 25, 2019

Unfortunately that did not work for me either. Ended up doing the following:

const DDB = this.dynamoose.ddb();

AWS.config.update({
  region: DDB.config.region,
  endpoint: DDB.config.endpoint,
});

const docClient = new AWS.DynamoDB.DocumentClient();
await docClient.delete({
  TableName: this.Model.$__.table.name,
  Key: {
    <hashKey>,
    createdAt,
  },
}).promise();
0reactions
fishcharliecommented, Nov 9, 2019

@dolsem The issue was inactive for a long period of time, and there was a proposed solution at the time the issue was closed. Reopening now. I haven’t been able to confirm this bug or anything tho. PRs are always welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamoose - cannot query and where with 2 keys
I suspect createdAt is not a range key of your table / index. You need to either do .filter('createdAt').ge(date) or modify your table ......
Read more >
API (GraphQL) - Index your data with keys - Amplify Docs
The @key directive makes it simple to configure custom index structures for @model types. - AWS Amplify Docs.
Read more >
DynamoDB Keys - Everything You Need To Know - Dynobase
Learn about different DynamoDB keys (primary simple/composite key, local/global secondary key) + when and how you can use them.
Read more >
Improving data access with secondary indexes
Local secondary indexes are created at the same time that you create a table. You cannot add a local secondary index to an...
Read more >
dynogels - npm
Simplified data modeling and mapping to DynamoDB types ... You can configure dynogels to automatically add createdAt and updatedAt timestamp ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found