{"action":"created","comment":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/comments/58364235","id":58364235,"diff_hunk":"@@ -1,13 +1,32 @@\n+import logging\n+\n from django.apps import AppConfig\n+from django.db import OperationalError, ProgrammingError\n+\n+log = logging.getLogger(__name__)\n \n \n class CoreAppConfig(AppConfig):\n     name = 'ecommerce.core'\n     verbose_name = 'Core'\n \n+    OPERATIONAL_ERROR_MESSAGE = 'DB error when validating configuration - most likely DB was not created yet - skipping'\n+\n     def ready(self):\n         super(CoreAppConfig, self).ready()\n \n         # Ensures that the initialized Celery app is loaded when Django starts.\n         # Allows Celery tasks to bind themselves to an initialized instance of the Celery library.\n         from ecommerce import celery_app  # pylint: disable=unused-variable\n+\n+        from ecommerce.core.models import validate_configuration\n+        # Operational error means database did not contain SiteConfiguration table - ok to skip since it means there\n+        # are no SiteConfiguration models to validate. Also, this exception was only observed in tests and test run\n+        # just fine with this suppression - most likely test code hit this line before the DB is populated\n+        try:\n+            # Here we're are consciously violating Django's warning about not interacting with DB in AppConfig.ready\n+            # We know what we're doing, have considered a couple of other approaches and discussed it in great length:\n+            # https://github.com/edx/ecommerce/pull/630#discussion-diff-58026881\n+            validate_configuration()\n+        except (OperationalError, ProgrammingError):","path":"ecommerce/core/config.py","position":31,"original_position":31,"commit_id":"60b024a80416a51c9e3c6e322fbba7a7dee3dfa3","original_commit_id":"60b024a80416a51c9e3c6e322fbba7a7dee3dfa3","user":{"login":"e-kolpakov","id":3330048,"avatar_url":"https://avatars.githubusercontent.com/u/3330048?v=3","gravatar_id":"","url":"https://api.github.com/users/e-kolpakov","html_url":"https://github.com/e-kolpakov","followers_url":"https://api.github.com/users/e-kolpakov/followers","following_url":"https://api.github.com/users/e-kolpakov/following{/other_user}","gists_url":"https://api.github.com/users/e-kolpakov/gists{/gist_id}","starred_url":"https://api.github.com/users/e-kolpakov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e-kolpakov/subscriptions","organizations_url":"https://api.github.com/users/e-kolpakov/orgs","repos_url":"https://api.github.com/users/e-kolpakov/repos","events_url":"https://api.github.com/users/e-kolpakov/events{/privacy}","received_events_url":"https://api.github.com/users/e-kolpakov/received_events","type":"User","site_admin":false},"body":"@clintonb @douglashall I've run a couple of other management commands with empty database and it looks like `OperationalError` and `ProgrammingError` are the only two exceptions raised. However, there are a couple of tother exception types defined in django.db.utils right next to them, all inheriting from `DatabaseError`. Do you think it would be better to catch less-specific `DatabaseError` exception here?","created_at":"2016-04-04T11:53:52Z","updated_at":"2016-04-04T11:53:52Z","html_url":"https://github.com/edx/ecommerce/pull/655#discussion_r58364235","pull_request_url":"https://api.github.com/repos/edx/ecommerce/pulls/655","_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments/58364235"},"html":{"href":"https://github.com/edx/ecommerce/pull/655#discussion_r58364235"},"pull_request":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/655"}}},"pull_request":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/655","id":65123849,"html_url":"https://github.com/edx/ecommerce/pull/655","diff_url":"https://github.com/edx/ecommerce/pull/655.diff","patch_url":"https://github.com/edx/ecommerce/pull/655.patch","issue_url":"https://api.github.com/repos/edx/ecommerce/issues/655","number":655,"state":"open","locked":false,"title":"Validate site configuration on startup","user":{"login":"e-kolpakov","id":3330048,"avatar_url":"https://avatars.githubusercontent.com/u/3330048?v=3","gravatar_id":"","url":"https://api.github.com/users/e-kolpakov","html_url":"https://github.com/e-kolpakov","followers_url":"https://api.github.com/users/e-kolpakov/followers","following_url":"https://api.github.com/users/e-kolpakov/following{/other_user}","gists_url":"https://api.github.com/users/e-kolpakov/gists{/gist_id}","starred_url":"https://api.github.com/users/e-kolpakov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e-kolpakov/subscriptions","organizations_url":"https://api.github.com/users/e-kolpakov/orgs","repos_url":"https://api.github.com/users/e-kolpakov/repos","events_url":"https://api.github.com/users/e-kolpakov/events{/privacy}","received_events_url":"https://api.github.com/users/e-kolpakov/received_events","type":"User","site_admin":false},"body":"**Description:** This PR reintroduces startup validation added in #630 with catching proper exceptions.\r\n**Merge deadline:** 8 Apr\r\n**Dependencies:** https://github.com/edx/ecommerce/pull/654\r\n**Related:** [Discovery document]\r\n(https://docs.google.com/document/d/17BRYvkO4ETvBV9TFodElpbJaK4oze7e0mNqf9ztnGnA/edit#heading=h.70eeasm5mr1q)\r\n**Sandbox:** \r\n* edX site: [LMS](http://pr11898.sandbox.opencraft.com), [Studio](http://studio.pr11898.sandbox.opencraft.com), [eCommerce](https://ecommerce.pr11898.sandbox.opencraft.com)\r\n* WL site: [LMS](http://wlsite.pr11898.sandbox.opencraft.com), [eCommerce](https://ecommerce.wlsite.pr11898.sandbox.opencraft.com)\r\n\r\n**JIRA:** [WL-362](https://openedx.atlassian.net/browse/WL-362), [WL-390](https://openedx.atlassian.net/browse/WL-390)\r\n\r\n**Testing instructions:** See #630 ","created_at":"2016-04-04T10:28:32Z","updated_at":"2016-04-04T11:53:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0067ba654ef1da95cebd655b033e767c61cbd12f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/ecommerce/pulls/655/commits","review_comments_url":"https://api.github.com/repos/edx/ecommerce/pulls/655/comments","review_comment_url":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/ecommerce/issues/655/comments","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/60b024a80416a51c9e3c6e322fbba7a7dee3dfa3","head":{"label":"open-craft:ekolpakov/validate_site_configuration_on_startup","ref":"ekolpakov/validate_site_configuration_on_startup","sha":"60b024a80416a51c9e3c6e322fbba7a7dee3dfa3","user":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"repo":{"id":52981525,"name":"ecommerce","full_name":"open-craft/ecommerce","owner":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/open-craft/ecommerce","description":"Django application used to manage edX's product catalog and handle orders for those products","fork":true,"url":"https://api.github.com/repos/open-craft/ecommerce","forks_url":"https://api.github.com/repos/open-craft/ecommerce/forks","keys_url":"https://api.github.com/repos/open-craft/ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/open-craft/ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/open-craft/ecommerce/teams","hooks_url":"https://api.github.com/repos/open-craft/ecommerce/hooks","issue_events_url":"https://api.github.com/repos/open-craft/ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/open-craft/ecommerce/events","assignees_url":"https://api.github.com/repos/open-craft/ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/open-craft/ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/open-craft/ecommerce/tags","blobs_url":"https://api.github.com/repos/open-craft/ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/open-craft/ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/open-craft/ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/open-craft/ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/open-craft/ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/open-craft/ecommerce/languages","stargazers_url":"https://api.github.com/repos/open-craft/ecommerce/stargazers","contributors_url":"https://api.github.com/repos/open-craft/ecommerce/contributors","subscribers_url":"https://api.github.com/repos/open-craft/ecommerce/subscribers","subscription_url":"https://api.github.com/repos/open-craft/ecommerce/subscription","commits_url":"https://api.github.com/repos/open-craft/ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/open-craft/ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/open-craft/ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/open-craft/ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/open-craft/ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/open-craft/ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/open-craft/ecommerce/merges","archive_url":"https://api.github.com/repos/open-craft/ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/open-craft/ecommerce/downloads","issues_url":"https://api.github.com/repos/open-craft/ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/open-craft/ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/open-craft/ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/open-craft/ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/open-craft/ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/open-craft/ecommerce/releases{/id}","deployments_url":"https://api.github.com/repos/open-craft/ecommerce/deployments","created_at":"2016-03-02T17:15:14Z","updated_at":"2016-03-02T17:15:17Z","pushed_at":"2016-04-04T11:17:25Z","git_url":"git://github.com/open-craft/ecommerce.git","ssh_url":"git@github.com:open-craft/ecommerce.git","clone_url":"https://github.com/open-craft/ecommerce.git","svn_url":"https://github.com/open-craft/ecommerce","homepage":"http://open-edx-ecommerce-guide.readthedocs.org","size":3409,"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":"c066605b32321b5632665d0b450c35a8c5b9f0d2","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":30175039,"name":"ecommerce","full_name":"edx/ecommerce","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/ecommerce","description":"Django application used to manage edX's product catalog and handle orders for those products.","fork":false,"url":"https://api.github.com/repos/edx/ecommerce","forks_url":"https://api.github.com/repos/edx/ecommerce/forks","keys_url":"https://api.github.com/repos/edx/ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce/events","assignees_url":"https://api.github.com/repos/edx/ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce/merges","archive_url":"https://api.github.com/repos/edx/ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce/releases{/id}","deployments_url":"https://api.github.com/repos/edx/ecommerce/deployments","created_at":"2015-02-02T06:55:15Z","updated_at":"2016-03-31T00:55:15Z","pushed_at":"2016-04-04T11:17:25Z","git_url":"git://github.com/edx/ecommerce.git","ssh_url":"git@github.com:edx/ecommerce.git","clone_url":"https://github.com/edx/ecommerce.git","svn_url":"https://github.com/edx/ecommerce","homepage":"","size":9960,"stargazers_count":29,"watchers_count":29,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":11,"forks":31,"open_issues":11,"watchers":29,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/655"},"html":{"href":"https://github.com/edx/ecommerce/pull/655"},"issue":{"href":"https://api.github.com/repos/edx/ecommerce/issues/655"},"comments":{"href":"https://api.github.com/repos/edx/ecommerce/issues/655/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/655/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/655/commits"},"statuses":{"href":"https://api.github.com/repos/edx/ecommerce/statuses/60b024a80416a51c9e3c6e322fbba7a7dee3dfa3"}}}}