{"action":"created","issue":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5977","repository_url":"https://api.github.com/repos/rethinkdb/rethinkdb","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5977/labels{/name}","comments_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5977/comments","events_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5977/events","html_url":"https://github.com/rethinkdb/rethinkdb/issues/5977","id":166597328,"number":5977,"title":"Update using r.literal() in nested structure fails (?)","user":{"login":"tatsujin1","id":6277212,"avatar_url":"https://avatars.githubusercontent.com/u/6277212?v=3","gravatar_id":"","url":"https://api.github.com/users/tatsujin1","html_url":"https://github.com/tatsujin1","followers_url":"https://api.github.com/users/tatsujin1/followers","following_url":"https://api.github.com/users/tatsujin1/following{/other_user}","gists_url":"https://api.github.com/users/tatsujin1/gists{/gist_id}","starred_url":"https://api.github.com/users/tatsujin1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tatsujin1/subscriptions","organizations_url":"https://api.github.com/users/tatsujin1/orgs","repos_url":"https://api.github.com/users/tatsujin1/repos","events_url":"https://api.github.com/users/tatsujin1/events{/privacy}","received_events_url":"https://api.github.com/users/tatsujin1/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/labels/tp:bug","name":"tp:bug","color":"e102d8"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/119","html_url":"https://github.com/rethinkdb/rethinkdb/milestones/2.3.x","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/119/labels","id":1687920,"number":119,"title":"2.3.x","description":null,"creator":{"login":"danielmewes","id":505365,"avatar_url":"https://avatars.githubusercontent.com/u/505365?v=3","gravatar_id":"","url":"https://api.github.com/users/danielmewes","html_url":"https://github.com/danielmewes","followers_url":"https://api.github.com/users/danielmewes/followers","following_url":"https://api.github.com/users/danielmewes/following{/other_user}","gists_url":"https://api.github.com/users/danielmewes/gists{/gist_id}","starred_url":"https://api.github.com/users/danielmewes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielmewes/subscriptions","organizations_url":"https://api.github.com/users/danielmewes/orgs","repos_url":"https://api.github.com/users/danielmewes/repos","events_url":"https://api.github.com/users/danielmewes/events{/privacy}","received_events_url":"https://api.github.com/users/danielmewes/received_events","type":"User","site_admin":false},"open_issues":57,"closed_issues":19,"state":"open","created_at":"2016-04-06T18:05:18Z","updated_at":"2016-07-22T18:13:36Z","due_on":null,"closed_at":null},"comments":8,"created_at":"2016-07-20T14:37:04Z","updated_at":"2016-07-22T22:22:51Z","closed_at":null,"body":"I have a database migration script that (amongst other things) converts a \"flat\" value into structured value. In my case I'm changing an id referencing a document in another table to storing the other document \"inline\".\r\n\r\nAnyway, to specifics.\r\n\r\nGiven the following document:\r\n```\r\n{\r\n   'id': 'test', \r\n   'data': 'flat_value' \r\n}\r\n```\r\nAnd then doing an update, replacing `data` with a structured value that contains `r.literal()` (and in my case a lot of other things).\r\nPerforming the write works fine. Or at least appears to:\r\n```\r\n>> table.get('test').update({\r\n   'data': {\r\n       'nested': r.literal()\r\n    }\r\n}).run()\r\n{\r\n   'replaced': 1,\r\n   'skipped': 0,\r\n   'unchanged': 0,\r\n   'inserted': 0,\r\n   'deleted': 0,\r\n   'errors': 0\r\n}\r\n```\r\n\r\nNo error. However, attempting to retrieve the document fails:\r\n\r\n```\r\n>> table.get('test').run()\r\nReqlDriverError: Unknown pseudo-type LITERAL\r\n```\r\n\r\nThis happens only when _replacing_ an existing value with an object that contains r.literal().\r\nGiven the original document and adding a new field works fine:\r\n```\r\n>> table.get('test').update({\r\n   'new_data': {\r\n      'nested': r.literal()\r\n   }\r\n}).run()\r\n>> table.get('test').run()\r\n{\r\n   'id': 'test',\r\n   'data': 'flat_value',\r\n   'new_data': { }\r\n}\r\n```\r\n\r\nedit: shortened queries\r\nedit2: fixed output of last query"},"comment":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/comments/234671409","html_url":"https://github.com/rethinkdb/rethinkdb/issues/5977#issuecomment-234671409","issue_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5977","id":234671409,"user":{"login":"mlucy","id":1777134,"avatar_url":"https://avatars.githubusercontent.com/u/1777134?v=3","gravatar_id":"","url":"https://api.github.com/users/mlucy","html_url":"https://github.com/mlucy","followers_url":"https://api.github.com/users/mlucy/followers","following_url":"https://api.github.com/users/mlucy/following{/other_user}","gists_url":"https://api.github.com/users/mlucy/gists{/gist_id}","starred_url":"https://api.github.com/users/mlucy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlucy/subscriptions","organizations_url":"https://api.github.com/users/mlucy/orgs","repos_url":"https://api.github.com/users/mlucy/repos","events_url":"https://api.github.com/users/mlucy/events{/privacy}","received_events_url":"https://api.github.com/users/mlucy/received_events","type":"User","site_admin":false},"created_at":"2016-07-22T22:22:51Z","updated_at":"2016-07-22T22:22:51Z","body":"When I say \"A literal outside the righthand side of a merge is just ignored\", I mean that `{a: foo}` and `{a: r.literal(foo)}` are identical, and also that `{a: 1, b: r.literal()}` and `{a: 1}` are identical.\r\n\r\n@danielmewes -- I think treating `r.literal()` fields as `NULL` would be really bad.  Unless I'm misunderstanding the proposal, `merge` as it's currently implemented would cause `r({}).merge({foo: {bar: r.literal()}})` to return `{foo: {bar: r.literal()}}` which would be `{foo: {bar: NULL}}`, while `r({foo: {}}).merge({foo: {bar: r.literal()}})` would return `{foo: {})`.\r\n\r\n---\r\n\r\nI don't think it would be a huge hassle to change the object interface so that you use an iterator to access the fields instead, and you can pass in an option indicating whether you want the iterator to see empty `r.literal()`s or not (which only `merge` and maybe like one other thing would).\r\n\r\nAfter thinking about it, though, I think the cleanest option would actually be to tag objects with whether or not they contain a nested literal.  I think we currently have (or should have) the rule that objects returned by executing ReQL never contain `r.literal()`, so we'd only have to tag literal objects provided by the query, which means it won't slow things down much (if at all) and won't be that much new code."}}
{"actor":{"display_login":"mlucy"}}