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

'name' keyword is reserved on update but not for insert #58

Open
calvinlfer opened this issue Sep 29, 2015 · 3 comments
Open

'name' keyword is reserved on update but not for insert #58

calvinlfer opened this issue Sep 29, 2015 · 3 comments
Milestone

Comments

@calvinlfer
Copy link

Hey Victor,

I notice that the name property is reserved when trying to do an update but not when trying to do an insert.

Here's an example of what I mean:

let insertEntry = createTable.then(
    function (data) {
        //return a promise (will automatically not wrap in another promise) thanks to JS awesomeness
        //if entry exists - will overwrite
        return dynasty
            .table('calvinTable')
            .insert({
                id: '1',
                name: 'calvin'
            });
    }
    // don't have an error handler here because the 'then' above took care of it
    // really we should be using catch instead of supplying a success and error handler
);

let queryEntryThatWasJustInserted = insertEntry.then(
    function (data) { //data is unwrapped promise
        //return a promise (will automatically not wrap in another promise)
        console.log('Item was inserted successfully');
        return dynasty
            .table('calvinTable')
            .find({hash: "1"});
    },
    function (err) {
        //uh oh previous step had a problem
    }
);

After that I try to update the entry that I just inserted

let updateAfterQuery = queryResults.then(
    function (data) {
        //return a promise (will automatically not wrap in another promise)
        return dynasty
            .table('calvinTable')
            .update('1', {
                name: 'calvin2',
                scala: 'isawesome'
            });
    }
);

let updateResults = updateAfterQuery.then(
    function (data) {   //data is unwrapped promise
        console.log('updated:');
        console.log(data);
    },
    function (err) {
        console.log("Uh oh, that didn't work");
        console.log(err);
    }
);

I get a okay for the table insert

Item was inserted successfully
The results are in: 
{ name: 'calvin', id: '1' }

But I get a validation exception on the update

Uh oh, that didn't work
{ [ValidationException: Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: name]
  cause: 
   { [ValidationException: Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: name]
     message: 'Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: name',
     code: 'ValidationException',
     time: Mon Sep 28 2015 21:28:17 GMT-0400 (Eastern Daylight Time),
     statusCode: 400,
     retryable: false,
     retryDelay: 0 },
  isOperational: true,
  code: 'ValidationException',
  time: Mon Sep 28 2015 21:28:17 GMT-0400 (Eastern Daylight Time),
  statusCode: 400,
  retryable: false,
  retryDelay: 0 }
@victorquinn
Copy link
Owner

Oh interesting! That's actually a Dynamo quirk, not a Dynasty one.

We don't do any validation on what's passed along to Dynamo at current.

Here is the list of reserved attribute names in Dynamo

You'll see that "NAME" is on there.

We should add a check in Dynasty if you try to provide any object on insert or update that includes one of those reserved words and return an error so it doesn't go through to Amazon.

@victorquinn victorquinn added this to the 0.2 milestone Sep 29, 2015
@calvinlfer
Copy link
Author

Thanks for confirming!

@williamcoates
Copy link
Contributor

I believe this was fixed by #64, can you check the latest npm (0.2.4) and confirm this was fixed ?

@victorquinn victorquinn modified the milestones: 1.0, 0.2 Mar 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants