{"action":"created","issue":{"url":"https://api.github.com/repos/epha/model/issues/20","labels_url":"https://api.github.com/repos/epha/model/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/epha/model/issues/20/comments","events_url":"https://api.github.com/repos/epha/model/issues/20/events","html_url":"https://github.com/epha/model/issues/20","id":75109450,"number":20,"title":"putItem conditional expression problem","user":{"login":"flootr","id":9202899,"avatar_url":"https://avatars.githubusercontent.com/u/9202899?v=3","gravatar_id":"","url":"https://api.github.com/users/flootr","html_url":"https://github.com/flootr","followers_url":"https://api.github.com/users/flootr/followers","following_url":"https://api.github.com/users/flootr/following{/other_user}","gists_url":"https://api.github.com/users/flootr/gists{/gist_id}","starred_url":"https://api.github.com/users/flootr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flootr/subscriptions","organizations_url":"https://api.github.com/users/flootr/orgs","repos_url":"https://api.github.com/users/flootr/repos","events_url":"https://api.github.com/users/flootr/events{/privacy}","received_events_url":"https://api.github.com/users/flootr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-11T06:37:29Z","updated_at":"2015-05-11T09:33:46Z","closed_at":null,"body":"There is a problem with `putItem()` if we want to replace an item that already exists in the database. My evaluation shows, that the problem is that we send an `ConditionalExpression` on every putItem request.\r\n\r\n`lib/sugar/items/create.js`\r\n\r\nOur code looks like:\r\n```javascript\r\nvar params = {\r\n  Item: item,\r\n  ConditionExpression: condition,\r\n  ExpressionAttributeNames: names,\r\n  ExpressionAttributeValues: values\r\n};\r\n\r\nreturn dynamo.putItem(client, tableName, params);\r\n```\r\n\r\nAt the moment this leads to a `ConditionalCheckFailedException`. If we only send an `Item` attribute, the behaviour is expected.\r\n\r\nDo we need this `ConditionalExpression` or can we leave it out? @Jonas74 @meaku "},"comment":{"url":"https://api.github.com/repos/epha/model/issues/comments/100833109","html_url":"https://github.com/epha/model/issues/20#issuecomment-100833109","issue_url":"https://api.github.com/repos/epha/model/issues/20","id":100833109,"user":{"login":"meaku","id":1265125,"avatar_url":"https://avatars.githubusercontent.com/u/1265125?v=3","gravatar_id":"","url":"https://api.github.com/users/meaku","html_url":"https://github.com/meaku","followers_url":"https://api.github.com/users/meaku/followers","following_url":"https://api.github.com/users/meaku/following{/other_user}","gists_url":"https://api.github.com/users/meaku/gists{/gist_id}","starred_url":"https://api.github.com/users/meaku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meaku/subscriptions","organizations_url":"https://api.github.com/users/meaku/orgs","repos_url":"https://api.github.com/users/meaku/repos","events_url":"https://api.github.com/users/meaku/events{/privacy}","received_events_url":"https://api.github.com/users/meaku/received_events","type":"User","site_admin":false},"created_at":"2015-05-11T09:33:46Z","updated_at":"2015-05-11T09:33:46Z","body":"That's actually wanted behavior: We have two different sugar functions on top of putItem with different semantics: \r\n\r\n## create \r\nCreates an item, but doesn't replace if item already exists. That's why we use the `ConditionExpression` to ensure no item with the given __hash__ and __range__ doesn't exist already. \r\n\r\n## upsert\r\nCreates or replaces and item. Uses putItem internally but doesn't use a condition expression. This means it replaces if it exists and creates if it doesn't exit already. \r\n\r\nCan you add this information in the docs and update the tests accordingly? @flootr?"}}