{"action":"created","comment":{"url":"https://api.github.com/repos/closeio/mongoengine/pulls/comments/79674872","id":79674872,"diff_hunk":"@@ -488,7 +488,13 @@ def reload(self):\n         \"\"\"\n         id_field = self._meta['id_field']\n         collection = self._get_collection()\n-        son = collection.find_one(self._db_object_key)\n+        # If this is a lazy object, we only have the ID field and don't want to\n+        # call _db_object_key, since _db_object_key could fetch (reload) the\n+        # object.\n+        if self._lazy:\n+            son = collection.find_one({ '_id': self.pk })\n+        else:\n+            son = collection.find_one(self._db_object_key)","path":"mongoengine/document.py","position":29,"original_position":29,"commit_id":"8771328720451008d3a2c411c3c9eca8b65495a9","original_commit_id":"8771328720451008d3a2c411c3c9eca8b65495a9","user":{"login":"wojcikstefan","id":1718372,"avatar_url":"https://avatars.githubusercontent.com/u/1718372?v=3","gravatar_id":"","url":"https://api.github.com/users/wojcikstefan","html_url":"https://github.com/wojcikstefan","followers_url":"https://api.github.com/users/wojcikstefan/followers","following_url":"https://api.github.com/users/wojcikstefan/following{/other_user}","gists_url":"https://api.github.com/users/wojcikstefan/gists{/gist_id}","starred_url":"https://api.github.com/users/wojcikstefan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wojcikstefan/subscriptions","organizations_url":"https://api.github.com/users/wojcikstefan/orgs","repos_url":"https://api.github.com/users/wojcikstefan/repos","events_url":"https://api.github.com/users/wojcikstefan/events{/privacy}","received_events_url":"https://api.github.com/users/wojcikstefan/received_events","type":"User","site_admin":false},"body":"What happens if we have a doc with a shard key on multiple fields, and you fetch a doc with `Doc.objects.only('id').first()` and then call `doc.reload()`. Will it incorrectly call `find_one` with `{ other_fields: None }`?","created_at":"2016-09-20T18:05:02Z","updated_at":"2016-09-20T18:05:35Z","html_url":"https://github.com/closeio/mongoengine/pull/17#discussion_r79674872","pull_request_url":"https://api.github.com/repos/closeio/mongoengine/pulls/17","_links":{"self":{"href":"https://api.github.com/repos/closeio/mongoengine/pulls/comments/79674872"},"html":{"href":"https://github.com/closeio/mongoengine/pull/17#discussion_r79674872"},"pull_request":{"href":"https://api.github.com/repos/closeio/mongoengine/pulls/17"}}},"pull_request":{"url":"https://api.github.com/repos/closeio/mongoengine/pulls/17","id":85894481,"html_url":"https://github.com/closeio/mongoengine/pull/17","diff_url":"https://github.com/closeio/mongoengine/pull/17.diff","patch_url":"https://github.com/closeio/mongoengine/pull/17.patch","issue_url":"https://api.github.com/repos/closeio/mongoengine/issues/17","number":17,"state":"open","locked":false,"title":"Reload lazy objects to get full shard key when accessing _db_object_key","user":{"login":"thomasst","id":68381,"avatar_url":"https://avatars.githubusercontent.com/u/68381?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasst","html_url":"https://github.com/thomasst","followers_url":"https://api.github.com/users/thomasst/followers","following_url":"https://api.github.com/users/thomasst/following{/other_user}","gists_url":"https://api.github.com/users/thomasst/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasst/subscriptions","organizations_url":"https://api.github.com/users/thomasst/orgs","repos_url":"https://api.github.com/users/thomasst/repos","events_url":"https://api.github.com/users/thomasst/events{/privacy}","received_events_url":"https://api.github.com/users/thomasst/received_events","type":"User","site_admin":false},"body":"Fixes https://rollbar.com/ElasticInc/Close.io/items/1628/\r\n\r\nLet's say you have an object with a reference. Then `obj.ref.delete()` currently does not fetch the referenced object, and would just delete the referenced object by ID. However, with `findAndModify` we need the full shard key, which means we need to fetch the referenced object, or somehow give a hint. This PR simply changes `_db_object_key` to trigger an object reload for lazy objects, so `obj.ref.delete()` would first fetch the referenced object, and then delete it using the full shard key.\r\n\r\n@closeio/engineering please review.\r\n","created_at":"2016-09-20T00:51:16Z","updated_at":"2016-09-20T18:05:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3ee5c8ebbb990e1533368347c1b53838cd08c1f0","assignee":{"login":"thomasst","id":68381,"avatar_url":"https://avatars.githubusercontent.com/u/68381?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasst","html_url":"https://github.com/thomasst","followers_url":"https://api.github.com/users/thomasst/followers","following_url":"https://api.github.com/users/thomasst/following{/other_user}","gists_url":"https://api.github.com/users/thomasst/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasst/subscriptions","organizations_url":"https://api.github.com/users/thomasst/orgs","repos_url":"https://api.github.com/users/thomasst/repos","events_url":"https://api.github.com/users/thomasst/events{/privacy}","received_events_url":"https://api.github.com/users/thomasst/received_events","type":"User","site_admin":false},"assignees":[{"login":"thomasst","id":68381,"avatar_url":"https://avatars.githubusercontent.com/u/68381?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasst","html_url":"https://github.com/thomasst","followers_url":"https://api.github.com/users/thomasst/followers","following_url":"https://api.github.com/users/thomasst/following{/other_user}","gists_url":"https://api.github.com/users/thomasst/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasst/subscriptions","organizations_url":"https://api.github.com/users/thomasst/orgs","repos_url":"https://api.github.com/users/thomasst/repos","events_url":"https://api.github.com/users/thomasst/events{/privacy}","received_events_url":"https://api.github.com/users/thomasst/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/closeio/mongoengine/pulls/17/commits","review_comments_url":"https://api.github.com/repos/closeio/mongoengine/pulls/17/comments","review_comment_url":"https://api.github.com/repos/closeio/mongoengine/pulls/comments{/number}","comments_url":"https://api.github.com/repos/closeio/mongoengine/issues/17/comments","statuses_url":"https://api.github.com/repos/closeio/mongoengine/statuses/8771328720451008d3a2c411c3c9eca8b65495a9","head":{"label":"closeio:lazy-db-object-key","ref":"lazy-db-object-key","sha":"8771328720451008d3a2c411c3c9eca8b65495a9","user":{"login":"closeio","id":437267,"avatar_url":"https://avatars.githubusercontent.com/u/437267?v=3","gravatar_id":"","url":"https://api.github.com/users/closeio","html_url":"https://github.com/closeio","followers_url":"https://api.github.com/users/closeio/followers","following_url":"https://api.github.com/users/closeio/following{/other_user}","gists_url":"https://api.github.com/users/closeio/gists{/gist_id}","starred_url":"https://api.github.com/users/closeio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/closeio/subscriptions","organizations_url":"https://api.github.com/users/closeio/orgs","repos_url":"https://api.github.com/users/closeio/repos","events_url":"https://api.github.com/users/closeio/events{/privacy}","received_events_url":"https://api.github.com/users/closeio/received_events","type":"Organization","site_admin":false},"repo":{"id":5533627,"name":"mongoengine","full_name":"closeio/mongoengine","owner":{"login":"closeio","id":437267,"avatar_url":"https://avatars.githubusercontent.com/u/437267?v=3","gravatar_id":"","url":"https://api.github.com/users/closeio","html_url":"https://github.com/closeio","followers_url":"https://api.github.com/users/closeio/followers","following_url":"https://api.github.com/users/closeio/following{/other_user}","gists_url":"https://api.github.com/users/closeio/gists{/gist_id}","starred_url":"https://api.github.com/users/closeio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/closeio/subscriptions","organizations_url":"https://api.github.com/users/closeio/orgs","repos_url":"https://api.github.com/users/closeio/repos","events_url":"https://api.github.com/users/closeio/events{/privacy}","received_events_url":"https://api.github.com/users/closeio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/closeio/mongoengine","description":"A Python Object-Document-Mapper for working with MongoDB","fork":true,"url":"https://api.github.com/repos/closeio/mongoengine","forks_url":"https://api.github.com/repos/closeio/mongoengine/forks","keys_url":"https://api.github.com/repos/closeio/mongoengine/keys{/key_id}","collaborators_url":"https://api.github.com/repos/closeio/mongoengine/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/closeio/mongoengine/teams","hooks_url":"https://api.github.com/repos/closeio/mongoengine/hooks","issue_events_url":"https://api.github.com/repos/closeio/mongoengine/issues/events{/number}","events_url":"https://api.github.com/repos/closeio/mongoengine/events","assignees_url":"https://api.github.com/repos/closeio/mongoengine/assignees{/user}","branches_url":"https://api.github.com/repos/closeio/mongoengine/branches{/branch}","tags_url":"https://api.github.com/repos/closeio/mongoengine/tags","blobs_url":"https://api.github.com/repos/closeio/mongoengine/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/closeio/mongoengine/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/closeio/mongoengine/git/refs{/sha}","trees_url":"https://api.github.com/repos/closeio/mongoengine/git/trees{/sha}","statuses_url":"https://api.github.com/repos/closeio/mongoengine/statuses/{sha}","languages_url":"https://api.github.com/repos/closeio/mongoengine/languages","stargazers_url":"https://api.github.com/repos/closeio/mongoengine/stargazers","contributors_url":"https://api.github.com/repos/closeio/mongoengine/contributors","subscribers_url":"https://api.github.com/repos/closeio/mongoengine/subscribers","subscription_url":"https://api.github.com/repos/closeio/mongoengine/subscription","commits_url":"https://api.github.com/repos/closeio/mongoengine/commits{/sha}","git_commits_url":"https://api.github.com/repos/closeio/mongoengine/git/commits{/sha}","comments_url":"https://api.github.com/repos/closeio/mongoengine/comments{/number}","issue_comment_url":"https://api.github.com/repos/closeio/mongoengine/issues/comments{/number}","contents_url":"https://api.github.com/repos/closeio/mongoengine/contents/{+path}","compare_url":"https://api.github.com/repos/closeio/mongoengine/compare/{base}...{head}","merges_url":"https://api.github.com/repos/closeio/mongoengine/merges","archive_url":"https://api.github.com/repos/closeio/mongoengine/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/closeio/mongoengine/downloads","issues_url":"https://api.github.com/repos/closeio/mongoengine/issues{/number}","pulls_url":"https://api.github.com/repos/closeio/mongoengine/pulls{/number}","milestones_url":"https://api.github.com/repos/closeio/mongoengine/milestones{/number}","notifications_url":"https://api.github.com/repos/closeio/mongoengine/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/closeio/mongoengine/labels{/name}","releases_url":"https://api.github.com/repos/closeio/mongoengine/releases{/id}","deployments_url":"https://api.github.com/repos/closeio/mongoengine/deployments","created_at":"2012-08-23T23:02:20Z","updated_at":"2016-08-16T23:59:09Z","pushed_at":"2016-09-20T00:51:16Z","git_url":"git://github.com/closeio/mongoengine.git","ssh_url":"git@github.com:closeio/mongoengine.git","clone_url":"https://github.com/closeio/mongoengine.git","svn_url":"https://github.com/closeio/mongoengine","homepage":"http://mongoengine.org","size":4629,"stargazers_count":26,"watchers_count":26,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":2,"forks":9,"open_issues":2,"watchers":26,"default_branch":"master"}},"base":{"label":"closeio:master","ref":"master","sha":"926b165fa4eb31b79da9ce0b0037997d455c597a","user":{"login":"closeio","id":437267,"avatar_url":"https://avatars.githubusercontent.com/u/437267?v=3","gravatar_id":"","url":"https://api.github.com/users/closeio","html_url":"https://github.com/closeio","followers_url":"https://api.github.com/users/closeio/followers","following_url":"https://api.github.com/users/closeio/following{/other_user}","gists_url":"https://api.github.com/users/closeio/gists{/gist_id}","starred_url":"https://api.github.com/users/closeio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/closeio/subscriptions","organizations_url":"https://api.github.com/users/closeio/orgs","repos_url":"https://api.github.com/users/closeio/repos","events_url":"https://api.github.com/users/closeio/events{/privacy}","received_events_url":"https://api.github.com/users/closeio/received_events","type":"Organization","site_admin":false},"repo":{"id":5533627,"name":"mongoengine","full_name":"closeio/mongoengine","owner":{"login":"closeio","id":437267,"avatar_url":"https://avatars.githubusercontent.com/u/437267?v=3","gravatar_id":"","url":"https://api.github.com/users/closeio","html_url":"https://github.com/closeio","followers_url":"https://api.github.com/users/closeio/followers","following_url":"https://api.github.com/users/closeio/following{/other_user}","gists_url":"https://api.github.com/users/closeio/gists{/gist_id}","starred_url":"https://api.github.com/users/closeio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/closeio/subscriptions","organizations_url":"https://api.github.com/users/closeio/orgs","repos_url":"https://api.github.com/users/closeio/repos","events_url":"https://api.github.com/users/closeio/events{/privacy}","received_events_url":"https://api.github.com/users/closeio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/closeio/mongoengine","description":"A Python Object-Document-Mapper for working with MongoDB","fork":true,"url":"https://api.github.com/repos/closeio/mongoengine","forks_url":"https://api.github.com/repos/closeio/mongoengine/forks","keys_url":"https://api.github.com/repos/closeio/mongoengine/keys{/key_id}","collaborators_url":"https://api.github.com/repos/closeio/mongoengine/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/closeio/mongoengine/teams","hooks_url":"https://api.github.com/repos/closeio/mongoengine/hooks","issue_events_url":"https://api.github.com/repos/closeio/mongoengine/issues/events{/number}","events_url":"https://api.github.com/repos/closeio/mongoengine/events","assignees_url":"https://api.github.com/repos/closeio/mongoengine/assignees{/user}","branches_url":"https://api.github.com/repos/closeio/mongoengine/branches{/branch}","tags_url":"https://api.github.com/repos/closeio/mongoengine/tags","blobs_url":"https://api.github.com/repos/closeio/mongoengine/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/closeio/mongoengine/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/closeio/mongoengine/git/refs{/sha}","trees_url":"https://api.github.com/repos/closeio/mongoengine/git/trees{/sha}","statuses_url":"https://api.github.com/repos/closeio/mongoengine/statuses/{sha}","languages_url":"https://api.github.com/repos/closeio/mongoengine/languages","stargazers_url":"https://api.github.com/repos/closeio/mongoengine/stargazers","contributors_url":"https://api.github.com/repos/closeio/mongoengine/contributors","subscribers_url":"https://api.github.com/repos/closeio/mongoengine/subscribers","subscription_url":"https://api.github.com/repos/closeio/mongoengine/subscription","commits_url":"https://api.github.com/repos/closeio/mongoengine/commits{/sha}","git_commits_url":"https://api.github.com/repos/closeio/mongoengine/git/commits{/sha}","comments_url":"https://api.github.com/repos/closeio/mongoengine/comments{/number}","issue_comment_url":"https://api.github.com/repos/closeio/mongoengine/issues/comments{/number}","contents_url":"https://api.github.com/repos/closeio/mongoengine/contents/{+path}","compare_url":"https://api.github.com/repos/closeio/mongoengine/compare/{base}...{head}","merges_url":"https://api.github.com/repos/closeio/mongoengine/merges","archive_url":"https://api.github.com/repos/closeio/mongoengine/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/closeio/mongoengine/downloads","issues_url":"https://api.github.com/repos/closeio/mongoengine/issues{/number}","pulls_url":"https://api.github.com/repos/closeio/mongoengine/pulls{/number}","milestones_url":"https://api.github.com/repos/closeio/mongoengine/milestones{/number}","notifications_url":"https://api.github.com/repos/closeio/mongoengine/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/closeio/mongoengine/labels{/name}","releases_url":"https://api.github.com/repos/closeio/mongoengine/releases{/id}","deployments_url":"https://api.github.com/repos/closeio/mongoengine/deployments","created_at":"2012-08-23T23:02:20Z","updated_at":"2016-08-16T23:59:09Z","pushed_at":"2016-09-20T00:51:16Z","git_url":"git://github.com/closeio/mongoengine.git","ssh_url":"git@github.com:closeio/mongoengine.git","clone_url":"https://github.com/closeio/mongoengine.git","svn_url":"https://github.com/closeio/mongoengine","homepage":"http://mongoengine.org","size":4629,"stargazers_count":26,"watchers_count":26,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":2,"forks":9,"open_issues":2,"watchers":26,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/closeio/mongoengine/pulls/17"},"html":{"href":"https://github.com/closeio/mongoengine/pull/17"},"issue":{"href":"https://api.github.com/repos/closeio/mongoengine/issues/17"},"comments":{"href":"https://api.github.com/repos/closeio/mongoengine/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/closeio/mongoengine/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/closeio/mongoengine/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/closeio/mongoengine/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/closeio/mongoengine/statuses/8771328720451008d3a2c411c3c9eca8b65495a9"}}}}
{"actor":{"display_login":"wojcikstefan"}}