{"action":"created","comment":{"url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/comments/215905570","pull_request_review_id":153274351,"id":215905570,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNTkwNTU3MA==","diff_hunk":"@@ -127,37 +129,49 @@ def evaluate(self, return_full=True, return_emitted=False):\n         try:\n             settings = get_queryobserver_settings()\n \n-            with transaction.atomic():\n-                # Obtain the observer state and lock it. This prevents an observer from being\n-                # processed in parallel from multiple different workers.\n-                observer, _ = models.Observer.objects.select_for_update().get_or_create(\n-                    id=self.id,\n-                    defaults={\n-                        'request': pickle.dumps(self._request),\n-                    },\n-                )\n+            for retry in range(MAX_INTEGRITY_ERROR_RETRIES):\n+                try:\n+                    with transaction.atomic():\n+                        # Obtain the observer state and lock it. This prevents an observer from being\n+                        # processed in parallel from multiple different workers.\n+                        observer, _ = models.Observer.objects.select_for_update().get_or_create(\n+                            id=self.id,\n+                            defaults={\n+                                'request': pickle.dumps(self._request),\n+                            },\n+                        )\n+\n+                        # Evaluate the observer.\n+                        start = time.time()\n+                        result = self._evaluate(observer, return_full, return_emitted)\n+                        duration = time.time() - start\n+\n+                        # Log slow observers.\n+                        if duration > settings['warnings']['max_processing_time']:\n+                            logger.warning(\n+                                \"Slow observed viewset ({})\".format(self._get_logging_id()),\n+                                extra=self._get_logging_extra(duration=duration)\n+                            )\n \n-                # Evaluate the observer.\n-                start = time.time()\n-                result = self._evaluate(observer, return_full, return_emitted)\n-                duration = time.time() - start\n+                        # Stop really slow observers.\n+                        if duration > settings['errors']['max_processing_time']:\n+                            logger.error(\n+                                \"Stopped extremely slow observed viewset ({})\".format(self._get_logging_id()),\n+                                extra=self._get_logging_extra(stopped=True, duration=duration)\n+                            )\n+                            observer.delete()\n \n-                # Log slow observers.\n-                if duration > settings['warnings']['max_processing_time']:\n-                    logger.warning(\n-                        \"Slow observed viewset ({})\".format(self._get_logging_id()),\n-                        extra=self._get_logging_extra(duration=duration)\n-                    )\n+                        return result\n+                except IntegrityError:\n+                    # If an IntegrityError occurrs we need to rollback the transaction and retry observer\n+                    # evaluation as another transaction may be creating an observer concurrently.\n+                    if retry == MAX_INTEGRITY_ERROR_RETRIES - 1:\n+                        raise\n \n-                # Stop really slow observers.\n-                if duration > settings['errors']['max_processing_time']:\n-                    logger.error(\n-                        \"Stopped extremely slow observed viewset ({})\".format(self._get_logging_id()),\n-                        extra=self._get_logging_extra(stopped=True, duration=duration)\n-                    )\n-                    observer.delete()\n+                    continue","path":"rest_framework_reactive/observer.py","position":78,"original_position":78,"commit_id":"8b5121814db4c15c9fde8c894ecc979ed8b50ec7","original_commit_id":"8b5121814db4c15c9fde8c894ecc979ed8b50ec7","user":{"login":"dblenkus","id":5970282,"node_id":"MDQ6VXNlcjU5NzAyODI=","avatar_url":"https://avatars2.githubusercontent.com/u/5970282?v=4","gravatar_id":"","url":"https://api.github.com/users/dblenkus","html_url":"https://github.com/dblenkus","followers_url":"https://api.github.com/users/dblenkus/followers","following_url":"https://api.github.com/users/dblenkus/following{/other_user}","gists_url":"https://api.github.com/users/dblenkus/gists{/gist_id}","starred_url":"https://api.github.com/users/dblenkus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dblenkus/subscriptions","organizations_url":"https://api.github.com/users/dblenkus/orgs","repos_url":"https://api.github.com/users/dblenkus/repos","events_url":"https://api.github.com/users/dblenkus/events{/privacy}","received_events_url":"https://api.github.com/users/dblenkus/received_events","type":"User","site_admin":false},"body":"This is unnecessary.","created_at":"2018-09-07T09:46:10Z","updated_at":"2018-09-07T09:47:06Z","html_url":"https://github.com/genialis/django-rest-framework-reactive/pull/45#discussion_r215905570","pull_request_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/45","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/comments/215905570"},"html":{"href":"https://github.com/genialis/django-rest-framework-reactive/pull/45#discussion_r215905570"},"pull_request":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/45"}}},"pull_request":{"url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/45","id":213869386,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEzODY5Mzg2","html_url":"https://github.com/genialis/django-rest-framework-reactive/pull/45","diff_url":"https://github.com/genialis/django-rest-framework-reactive/pull/45.diff","patch_url":"https://github.com/genialis/django-rest-framework-reactive/pull/45.patch","issue_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/issues/45","number":45,"state":"open","locked":false,"title":"Retry taking the observer lock on IntegrityError","user":{"login":"kostko","id":543739,"node_id":"MDQ6VXNlcjU0MzczOQ==","avatar_url":"https://avatars1.githubusercontent.com/u/543739?v=4","gravatar_id":"","url":"https://api.github.com/users/kostko","html_url":"https://github.com/kostko","followers_url":"https://api.github.com/users/kostko/followers","following_url":"https://api.github.com/users/kostko/following{/other_user}","gists_url":"https://api.github.com/users/kostko/gists{/gist_id}","starred_url":"https://api.github.com/users/kostko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kostko/subscriptions","organizations_url":"https://api.github.com/users/kostko/orgs","repos_url":"https://api.github.com/users/kostko/repos","events_url":"https://api.github.com/users/kostko/events{/privacy}","received_events_url":"https://api.github.com/users/kostko/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-09-07T09:30:48Z","updated_at":"2018-09-07T09:47:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"70f5cabf11b586870d426d560e24e84fd633a34b","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/45/commits","review_comments_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/45/comments","review_comment_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/comments{/number}","comments_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/issues/45/comments","statuses_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/statuses/8b5121814db4c15c9fde8c894ecc979ed8b50ec7","head":{"label":"kostko:fix/evaluate-integrity-err","ref":"fix/evaluate-integrity-err","sha":"8b5121814db4c15c9fde8c894ecc979ed8b50ec7","user":{"login":"kostko","id":543739,"node_id":"MDQ6VXNlcjU0MzczOQ==","avatar_url":"https://avatars1.githubusercontent.com/u/543739?v=4","gravatar_id":"","url":"https://api.github.com/users/kostko","html_url":"https://github.com/kostko","followers_url":"https://api.github.com/users/kostko/followers","following_url":"https://api.github.com/users/kostko/following{/other_user}","gists_url":"https://api.github.com/users/kostko/gists{/gist_id}","starred_url":"https://api.github.com/users/kostko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kostko/subscriptions","organizations_url":"https://api.github.com/users/kostko/orgs","repos_url":"https://api.github.com/users/kostko/repos","events_url":"https://api.github.com/users/kostko/events{/privacy}","received_events_url":"https://api.github.com/users/kostko/received_events","type":"User","site_admin":false},"repo":{"id":93070065,"node_id":"MDEwOlJlcG9zaXRvcnk5MzA3MDA2NQ==","name":"django-rest-framework-reactive","full_name":"kostko/django-rest-framework-reactive","owner":{"login":"kostko","id":543739,"node_id":"MDQ6VXNlcjU0MzczOQ==","avatar_url":"https://avatars1.githubusercontent.com/u/543739?v=4","gravatar_id":"","url":"https://api.github.com/users/kostko","html_url":"https://github.com/kostko","followers_url":"https://api.github.com/users/kostko/followers","following_url":"https://api.github.com/users/kostko/following{/other_user}","gists_url":"https://api.github.com/users/kostko/gists{/gist_id}","starred_url":"https://api.github.com/users/kostko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kostko/subscriptions","organizations_url":"https://api.github.com/users/kostko/orgs","repos_url":"https://api.github.com/users/kostko/repos","events_url":"https://api.github.com/users/kostko/events{/privacy}","received_events_url":"https://api.github.com/users/kostko/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kostko/django-rest-framework-reactive","description":"Making Django REST Framework reactive","fork":true,"url":"https://api.github.com/repos/kostko/django-rest-framework-reactive","forks_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/forks","keys_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/teams","hooks_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/hooks","issue_events_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/issues/events{/number}","events_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/events","assignees_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/assignees{/user}","branches_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/branches{/branch}","tags_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/tags","blobs_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/git/refs{/sha}","trees_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/statuses/{sha}","languages_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/languages","stargazers_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/stargazers","contributors_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/contributors","subscribers_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/subscribers","subscription_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/subscription","commits_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/commits{/sha}","git_commits_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/git/commits{/sha}","comments_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/comments{/number}","issue_comment_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/issues/comments{/number}","contents_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/contents/{+path}","compare_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/merges","archive_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/downloads","issues_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/issues{/number}","pulls_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/pulls{/number}","milestones_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/milestones{/number}","notifications_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/labels{/name}","releases_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/releases{/id}","deployments_url":"https://api.github.com/repos/kostko/django-rest-framework-reactive/deployments","created_at":"2017-06-01T15:07:48Z","updated_at":"2017-06-01T15:07:50Z","pushed_at":"2018-09-07T09:29:36Z","git_url":"git://github.com/kostko/django-rest-framework-reactive.git","ssh_url":"git@github.com:kostko/django-rest-framework-reactive.git","clone_url":"https://github.com/kostko/django-rest-framework-reactive.git","svn_url":"https://github.com/kostko/django-rest-framework-reactive","homepage":null,"size":107,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"genialis:master","ref":"master","sha":"869d6903601b1cbc14d1cb1022aacf287867b944","user":{"login":"genialis","id":2120224,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMjAyMjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2120224?v=4","gravatar_id":"","url":"https://api.github.com/users/genialis","html_url":"https://github.com/genialis","followers_url":"https://api.github.com/users/genialis/followers","following_url":"https://api.github.com/users/genialis/following{/other_user}","gists_url":"https://api.github.com/users/genialis/gists{/gist_id}","starred_url":"https://api.github.com/users/genialis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genialis/subscriptions","organizations_url":"https://api.github.com/users/genialis/orgs","repos_url":"https://api.github.com/users/genialis/repos","events_url":"https://api.github.com/users/genialis/events{/privacy}","received_events_url":"https://api.github.com/users/genialis/received_events","type":"Organization","site_admin":false},"repo":{"id":56757919,"node_id":"MDEwOlJlcG9zaXRvcnk1Njc1NzkxOQ==","name":"django-rest-framework-reactive","full_name":"genialis/django-rest-framework-reactive","owner":{"login":"genialis","id":2120224,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMjAyMjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2120224?v=4","gravatar_id":"","url":"https://api.github.com/users/genialis","html_url":"https://github.com/genialis","followers_url":"https://api.github.com/users/genialis/followers","following_url":"https://api.github.com/users/genialis/following{/other_user}","gists_url":"https://api.github.com/users/genialis/gists{/gist_id}","starred_url":"https://api.github.com/users/genialis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genialis/subscriptions","organizations_url":"https://api.github.com/users/genialis/orgs","repos_url":"https://api.github.com/users/genialis/repos","events_url":"https://api.github.com/users/genialis/events{/privacy}","received_events_url":"https://api.github.com/users/genialis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/genialis/django-rest-framework-reactive","description":"Making Django REST Framework reactive","fork":false,"url":"https://api.github.com/repos/genialis/django-rest-framework-reactive","forks_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/forks","keys_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/keys{/key_id}","collaborators_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/teams","hooks_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/hooks","issue_events_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/issues/events{/number}","events_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/events","assignees_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/assignees{/user}","branches_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/branches{/branch}","tags_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/tags","blobs_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/git/refs{/sha}","trees_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/git/trees{/sha}","statuses_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/statuses/{sha}","languages_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/languages","stargazers_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/stargazers","contributors_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/contributors","subscribers_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/subscribers","subscription_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/subscription","commits_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/commits{/sha}","git_commits_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/git/commits{/sha}","comments_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/comments{/number}","issue_comment_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/issues/comments{/number}","contents_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/contents/{+path}","compare_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/compare/{base}...{head}","merges_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/merges","archive_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/downloads","issues_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/issues{/number}","pulls_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls{/number}","milestones_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/milestones{/number}","notifications_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/labels{/name}","releases_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/releases{/id}","deployments_url":"https://api.github.com/repos/genialis/django-rest-framework-reactive/deployments","created_at":"2016-04-21T08:50:28Z","updated_at":"2018-08-06T11:51:37Z","pushed_at":"2018-09-07T09:30:49Z","git_url":"git://github.com/genialis/django-rest-framework-reactive.git","ssh_url":"git@github.com:genialis/django-rest-framework-reactive.git","clone_url":"https://github.com/genialis/django-rest-framework-reactive.git","svn_url":"https://github.com/genialis/django-rest-framework-reactive","homepage":null,"size":167,"stargazers_count":46,"watchers_count":46,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":3,"open_issues":2,"watchers":46,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/45"},"html":{"href":"https://github.com/genialis/django-rest-framework-reactive/pull/45"},"issue":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/issues/45"},"comments":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/issues/45/comments"},"review_comments":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/45/comments"},"review_comment":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/pulls/45/commits"},"statuses":{"href":"https://api.github.com/repos/genialis/django-rest-framework-reactive/statuses/8b5121814db4c15c9fde8c894ecc979ed8b50ec7"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"dblenkus"}}