{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/30800043","id":30800043,"diff_hunk":"@@ -0,0 +1,255 @@\n+\"\"\"\n+A baseclass for a generic client for accessing XBlock Scope.user_state field data.\n+\"\"\"\n+\n+from abc import abstractmethod\n+\n+from contracts import contract, new_contract, ContractsMeta\n+from opaque_keys.edx.keys import UsageKey\n+from xblock.fields import Scope, ScopeBase\n+\n+new_contract('UsageKey', UsageKey)\n+\n+\n+class XBlockUserStateClient(object):\n+    \"\"\"\n+    First stab at an interface for accessing XBlock User State. This will have\n+    use StudentModule as a backing store in the default case.\n+\n+    Scope/Goals:\n+    1. Mediate access to all student-specific state stored by XBlocks.\n+        a. This includes \"preferences\" and \"user_info\" (i.e. UserScope.ONE)\n+        b. This includes XBlock Asides.\n+        c. This may later include user_state_summary (i.e. UserScope.ALL).\n+        d. This may include group state in the future.\n+        e. This may include other key types + UserScope.ONE (e.g. Definition)\n+    2. Assume network service semantics.\n+        At some point, this will probably be calling out to an external service.\n+        Even if it doesn't, we want to be able to implement circuit breakers, so\n+        that a failure in StudentModule doesn't bring down the whole site.\n+        This also implies that the client is running as a user, and whatever is\n+        backing it is smart enough to do authorization checks.\n+    3. This does not yet cover export-related functionality.\n+\n+    Open Questions:\n+    1. Is it sufficient to just send the block_key in and extract course +\n+       version info from it?\n+    2. Do we want to use the username as the identifier? Privacy implications?\n+       Ease of debugging?\n+    3. Would a get_many_by_type() be useful?\n+    \"\"\"\n+\n+    __metaclass__ = ContractsMeta\n+\n+    class ServiceUnavailable(Exception):\n+        \"\"\"\n+        This error is raised if the service backing this client is currently unavailable.\n+        \"\"\"\n+        pass\n+\n+    class PermissionDenied(Exception):\n+        \"\"\"\n+        This error is raised if the caller is not allowed to access the requested data.\n+        \"\"\"\n+        pass\n+\n+    class DoesNotExist(Exception):\n+        \"\"\"\n+        This error is raised if the caller has requested data that does not exist.\n+        \"\"\"\n+        pass\n+\n+    @contract(\n+        username=\"basestring\",\n+        block_key=UsageKey,\n+        scope=ScopeBase,\n+        fields=\"seq(basestring)|set(basestring)|None\",","path":"lms/djangoapps/xblock_user_state/interface.py","position":66,"original_position":66,"commit_id":"122039ac58c97814a5116e7d41439dca44c258cb","original_commit_id":"0535dfd6299b652c4754538c475ce9832283d8cc","user":{"login":"cpennington","id":30236,"avatar_url":"https://avatars.githubusercontent.com/u/30236?v=3","gravatar_id":"","url":"https://api.github.com/users/cpennington","html_url":"https://github.com/cpennington","followers_url":"https://api.github.com/users/cpennington/followers","following_url":"https://api.github.com/users/cpennington/following{/other_user}","gists_url":"https://api.github.com/users/cpennington/gists{/gist_id}","starred_url":"https://api.github.com/users/cpennington/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpennington/subscriptions","organizations_url":"https://api.github.com/users/cpennington/orgs","repos_url":"https://api.github.com/users/cpennington/repos","events_url":"https://api.github.com/users/cpennington/events{/privacy}","received_events_url":"https://api.github.com/users/cpennington/received_events","type":"User","site_admin":false},"body":"Sadly, there's not a reasonable way (from what I could tell) to add new generics to pycontracts.","created_at":"2015-05-21T13:16:18Z","updated_at":"2015-05-21T13:16:18Z","html_url":"https://github.com/edx/edx-platform/pull/7789#discussion_r30800043","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/7789","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/30800043"},"html":{"href":"https://github.com/edx/edx-platform/pull/7789#discussion_r30800043"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7789"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/7789","id":33964061,"html_url":"https://github.com/edx/edx-platform/pull/7789","diff_url":"https://github.com/edx/edx-platform/pull/7789.diff","patch_url":"https://github.com/edx/edx-platform/pull/7789.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/7789","number":7789,"state":"closed","locked":false,"title":"Wrap access to CSM (inside FieldDataCache) to use the new interface","user":{"login":"cpennington","id":30236,"avatar_url":"https://avatars.githubusercontent.com/u/30236?v=3","gravatar_id":"","url":"https://api.github.com/users/cpennington","html_url":"https://github.com/cpennington","followers_url":"https://api.github.com/users/cpennington/followers","following_url":"https://api.github.com/users/cpennington/following{/other_user}","gists_url":"https://api.github.com/users/cpennington/gists{/gist_id}","starred_url":"https://api.github.com/users/cpennington/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpennington/subscriptions","organizations_url":"https://api.github.com/users/cpennington/orgs","repos_url":"https://api.github.com/users/cpennington/repos","events_url":"https://api.github.com/users/cpennington/events{/privacy}","received_events_url":"https://api.github.com/users/cpennington/received_events","type":"User","site_admin":false},"body":"This PR is the first step in swapping the backing store for XBlock `Scope.user_state` from being stored in `courseware.models.StudentModel` to a more performant/scalable backend. The goal of this particular PR is to isolate all access to `StudentModel` used for loading XBlocks field state (by the LMS) behind a single interface which we believe that we can write additional backends to.","created_at":"2015-04-23T15:01:35Z","updated_at":"2015-05-21T13:16:18Z","closed_at":"2015-05-20T20:11:07Z","merged_at":"2015-05-20T20:11:07Z","merge_commit_sha":"796ea5141c829b7808d2c920431a609619d44812","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/7789/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/7789/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/7789/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/122039ac58c97814a5116e7d41439dca44c258cb","head":{"label":"cpennington:wrap-csm","ref":"wrap-csm","sha":"122039ac58c97814a5116e7d41439dca44c258cb","user":{"login":"cpennington","id":30236,"avatar_url":"https://avatars.githubusercontent.com/u/30236?v=3","gravatar_id":"","url":"https://api.github.com/users/cpennington","html_url":"https://github.com/cpennington","followers_url":"https://api.github.com/users/cpennington/followers","following_url":"https://api.github.com/users/cpennington/following{/other_user}","gists_url":"https://api.github.com/users/cpennington/gists{/gist_id}","starred_url":"https://api.github.com/users/cpennington/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpennington/subscriptions","organizations_url":"https://api.github.com/users/cpennington/orgs","repos_url":"https://api.github.com/users/cpennington/repos","events_url":"https://api.github.com/users/cpennington/events{/privacy}","received_events_url":"https://api.github.com/users/cpennington/received_events","type":"User","site_admin":false},"repo":{"id":10688258,"name":"edx-platform","full_name":"cpennington/edx-platform","owner":{"login":"cpennington","id":30236,"avatar_url":"https://avatars.githubusercontent.com/u/30236?v=3","gravatar_id":"","url":"https://api.github.com/users/cpennington","html_url":"https://github.com/cpennington","followers_url":"https://api.github.com/users/cpennington/followers","following_url":"https://api.github.com/users/cpennington/following{/other_user}","gists_url":"https://api.github.com/users/cpennington/gists{/gist_id}","starred_url":"https://api.github.com/users/cpennington/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpennington/subscriptions","organizations_url":"https://api.github.com/users/cpennington/orgs","repos_url":"https://api.github.com/users/cpennington/repos","events_url":"https://api.github.com/users/cpennington/events{/privacy}","received_events_url":"https://api.github.com/users/cpennington/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cpennington/edx-platform","description":"the edX learning management system (LMS) and course authoring tool, Studio","fork":true,"url":"https://api.github.com/repos/cpennington/edx-platform","forks_url":"https://api.github.com/repos/cpennington/edx-platform/forks","keys_url":"https://api.github.com/repos/cpennington/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cpennington/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cpennington/edx-platform/teams","hooks_url":"https://api.github.com/repos/cpennington/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/cpennington/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/cpennington/edx-platform/events","assignees_url":"https://api.github.com/repos/cpennington/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/cpennington/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/cpennington/edx-platform/tags","blobs_url":"https://api.github.com/repos/cpennington/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cpennington/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cpennington/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/cpennington/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cpennington/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/cpennington/edx-platform/languages","stargazers_url":"https://api.github.com/repos/cpennington/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/cpennington/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/cpennington/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/cpennington/edx-platform/subscription","commits_url":"https://api.github.com/repos/cpennington/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/cpennington/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/cpennington/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/cpennington/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/cpennington/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/cpennington/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cpennington/edx-platform/merges","archive_url":"https://api.github.com/repos/cpennington/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cpennington/edx-platform/downloads","issues_url":"https://api.github.com/repos/cpennington/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/cpennington/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/cpennington/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/cpennington/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cpennington/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/cpennington/edx-platform/releases{/id}","created_at":"2013-06-14T12:13:54Z","updated_at":"2015-04-06T13:52:11Z","pushed_at":"2015-05-20T20:11:10Z","git_url":"git://github.com/cpennington/edx-platform.git","ssh_url":"git@github.com:cpennington/edx-platform.git","clone_url":"https://github.com/cpennington/edx-platform.git","svn_url":"https://github.com/cpennington/edx-platform","homepage":"http://code.edx.org/","size":399653,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"af69635f74ece217c2c0c3be133fa11278c5fcb2","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-05-21T03:10:46Z","pushed_at":"2015-05-21T13:15:12Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://openedx.org/","size":1942802,"stargazers_count":1933,"watchers_count":1933,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1113,"mirror_url":null,"open_issues_count":165,"forks":1113,"open_issues":165,"watchers":1933,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7789"},"html":{"href":"https://github.com/edx/edx-platform/pull/7789"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/7789"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/7789/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7789/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7789/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/122039ac58c97814a5116e7d41439dca44c258cb"}}}}