{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments/86244496","pull_request_review_id":6912247,"id":86244496,"diff_hunk":"@@ -3367,6 +3367,36 @@ def val(cls):\n \n     @classmethod\n     @provide_session\n+    def setdefault(cls, key, default, deserialize_json=False, session=None):\n+        \"\"\"\n+        Like a Python builtin dict object, setdefault returns the current value\n+        for a key, and if it isn't there, stores the default value and returns it.\n+\n+        :param key: Dict key for this Variable\n+        :type key: String\n+        :param: default: Default value to set and return if the variable\n+        isn't already in the DB\n+        :type: default: Mixed\n+        :param: deserialize_json: Store this as a JSON encoded value in the DB\n+         and un-encode it when retrieving a value\n+        :return: Mixed\n+        \"\"\"\n+        obj = session.query(cls).filter(cls.key == key).first()","path":"airflow/models.py","position":18,"original_position":18,"commit_id":"5320309f9afbbc68b76b3434bec59445be9d3a3d","original_commit_id":"5320309f9afbbc68b76b3434bec59445be9d3a3d","user":{"login":"gwax","id":235458,"avatar_url":"https://avatars.githubusercontent.com/u/235458?v=3","gravatar_id":"","url":"https://api.github.com/users/gwax","html_url":"https://github.com/gwax","followers_url":"https://api.github.com/users/gwax/followers","following_url":"https://api.github.com/users/gwax/following{/other_user}","gists_url":"https://api.github.com/users/gwax/gists{/gist_id}","starred_url":"https://api.github.com/users/gwax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwax/subscriptions","organizations_url":"https://api.github.com/users/gwax/orgs","repos_url":"https://api.github.com/users/gwax/repos","events_url":"https://api.github.com/users/gwax/events{/privacy}","received_events_url":"https://api.github.com/users/gwax/received_events","type":"User","site_admin":false},"body":"Would it make sense to reuse the `get` logic directly. Something like:\r\n\r\n```python\r\nexists = session.query(literal(True)).where(\r\n    session.query(cls).filter(cls.key == key).exists()\r\n    ).scalar()\r\nif not exists:\r\n    Variable.set(key, default, serialize_json=deserialize_json)\r\nreturn Variable.get(key, deserialize_json=deserialize_json)\r\n```\r\n\r\n(I haven't tested the exist query)","created_at":"2016-11-02T21:17:26Z","updated_at":"2016-11-02T21:17:26Z","html_url":"https://github.com/apache/incubator-airflow/pull/1765#discussion_r86244496","pull_request_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/1765","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments/86244496"},"html":{"href":"https://github.com/apache/incubator-airflow/pull/1765#discussion_r86244496"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/1765"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-airflow/pulls/1765","id":83179761,"html_url":"https://github.com/apache/incubator-airflow/pull/1765","diff_url":"https://github.com/apache/incubator-airflow/pull/1765.diff","patch_url":"https://github.com/apache/incubator-airflow/pull/1765.patch","issue_url":"https://api.github.com/repos/apache/incubator-airflow/issues/1765","number":1765,"state":"open","locked":false,"title":"[AIRFLOW-464] Add setdefault method to Variable","user":{"login":"btallman","id":173950,"avatar_url":"https://avatars.githubusercontent.com/u/173950?v=3","gravatar_id":"","url":"https://api.github.com/users/btallman","html_url":"https://github.com/btallman","followers_url":"https://api.github.com/users/btallman/followers","following_url":"https://api.github.com/users/btallman/following{/other_user}","gists_url":"https://api.github.com/users/btallman/gists{/gist_id}","starred_url":"https://api.github.com/users/btallman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btallman/subscriptions","organizations_url":"https://api.github.com/users/btallman/orgs","repos_url":"https://api.github.com/users/btallman/repos","events_url":"https://api.github.com/users/btallman/events{/privacy}","received_events_url":"https://api.github.com/users/btallman/received_events","type":"User","site_admin":false},"body":"Dear Airflow Maintainers,\r\n\r\nPlease accept this PR that addresses the following issues:\r\n- _https://issues.apache.org/jira/browse/AIRFLOW-464_\r\n\r\nThis was changed from adding a create_if_none flag to Variable.get based on feedback on this PR.\r\n\r\nTesting Done:\r\n- Added a test to test/core.py to cover this functionality","created_at":"2016-08-29T22:35:14Z","updated_at":"2016-11-02T21:17:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fb0d97c121c6d7cb700b06fdec591be7fbca0202","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/1765/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/1765/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-airflow/issues/1765/comments","statuses_url":"https://api.github.com/repos/apache/incubator-airflow/statuses/5320309f9afbbc68b76b3434bec59445be9d3a3d","head":{"label":"btallman:CreateIfNone_feature","ref":"CreateIfNone_feature","sha":"5320309f9afbbc68b76b3434bec59445be9d3a3d","user":{"login":"btallman","id":173950,"avatar_url":"https://avatars.githubusercontent.com/u/173950?v=3","gravatar_id":"","url":"https://api.github.com/users/btallman","html_url":"https://github.com/btallman","followers_url":"https://api.github.com/users/btallman/followers","following_url":"https://api.github.com/users/btallman/following{/other_user}","gists_url":"https://api.github.com/users/btallman/gists{/gist_id}","starred_url":"https://api.github.com/users/btallman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btallman/subscriptions","organizations_url":"https://api.github.com/users/btallman/orgs","repos_url":"https://api.github.com/users/btallman/repos","events_url":"https://api.github.com/users/btallman/events{/privacy}","received_events_url":"https://api.github.com/users/btallman/received_events","type":"User","site_admin":false},"repo":{"id":66884999,"name":"incubator-airflow","full_name":"btallman/incubator-airflow","owner":{"login":"btallman","id":173950,"avatar_url":"https://avatars.githubusercontent.com/u/173950?v=3","gravatar_id":"","url":"https://api.github.com/users/btallman","html_url":"https://github.com/btallman","followers_url":"https://api.github.com/users/btallman/followers","following_url":"https://api.github.com/users/btallman/following{/other_user}","gists_url":"https://api.github.com/users/btallman/gists{/gist_id}","starred_url":"https://api.github.com/users/btallman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btallman/subscriptions","organizations_url":"https://api.github.com/users/btallman/orgs","repos_url":"https://api.github.com/users/btallman/repos","events_url":"https://api.github.com/users/btallman/events{/privacy}","received_events_url":"https://api.github.com/users/btallman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/btallman/incubator-airflow","description":"Apache Airflow (Incubating)","fork":true,"url":"https://api.github.com/repos/btallman/incubator-airflow","forks_url":"https://api.github.com/repos/btallman/incubator-airflow/forks","keys_url":"https://api.github.com/repos/btallman/incubator-airflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/btallman/incubator-airflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/btallman/incubator-airflow/teams","hooks_url":"https://api.github.com/repos/btallman/incubator-airflow/hooks","issue_events_url":"https://api.github.com/repos/btallman/incubator-airflow/issues/events{/number}","events_url":"https://api.github.com/repos/btallman/incubator-airflow/events","assignees_url":"https://api.github.com/repos/btallman/incubator-airflow/assignees{/user}","branches_url":"https://api.github.com/repos/btallman/incubator-airflow/branches{/branch}","tags_url":"https://api.github.com/repos/btallman/incubator-airflow/tags","blobs_url":"https://api.github.com/repos/btallman/incubator-airflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/btallman/incubator-airflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/btallman/incubator-airflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/btallman/incubator-airflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/btallman/incubator-airflow/statuses/{sha}","languages_url":"https://api.github.com/repos/btallman/incubator-airflow/languages","stargazers_url":"https://api.github.com/repos/btallman/incubator-airflow/stargazers","contributors_url":"https://api.github.com/repos/btallman/incubator-airflow/contributors","subscribers_url":"https://api.github.com/repos/btallman/incubator-airflow/subscribers","subscription_url":"https://api.github.com/repos/btallman/incubator-airflow/subscription","commits_url":"https://api.github.com/repos/btallman/incubator-airflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/btallman/incubator-airflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/btallman/incubator-airflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/btallman/incubator-airflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/btallman/incubator-airflow/contents/{+path}","compare_url":"https://api.github.com/repos/btallman/incubator-airflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/btallman/incubator-airflow/merges","archive_url":"https://api.github.com/repos/btallman/incubator-airflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/btallman/incubator-airflow/downloads","issues_url":"https://api.github.com/repos/btallman/incubator-airflow/issues{/number}","pulls_url":"https://api.github.com/repos/btallman/incubator-airflow/pulls{/number}","milestones_url":"https://api.github.com/repos/btallman/incubator-airflow/milestones{/number}","notifications_url":"https://api.github.com/repos/btallman/incubator-airflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/btallman/incubator-airflow/labels{/name}","releases_url":"https://api.github.com/repos/btallman/incubator-airflow/releases{/id}","deployments_url":"https://api.github.com/repos/btallman/incubator-airflow/deployments","created_at":"2016-08-29T22:21:39Z","updated_at":"2016-08-29T22:21:41Z","pushed_at":"2016-11-02T19:14:15Z","git_url":"git://github.com/btallman/incubator-airflow.git","ssh_url":"git@github.com:btallman/incubator-airflow.git","clone_url":"https://github.com/btallman/incubator-airflow.git","svn_url":"https://github.com/btallman/incubator-airflow","homepage":"","size":10901,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"apache:master","ref":"master","sha":"26c2df33bea5f04378131e49e84d1b7e66b36b4b","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":33884891,"name":"incubator-airflow","full_name":"apache/incubator-airflow","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-airflow","description":"Apache Airflow (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-airflow","forks_url":"https://api.github.com/repos/apache/incubator-airflow/forks","keys_url":"https://api.github.com/repos/apache/incubator-airflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-airflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-airflow/teams","hooks_url":"https://api.github.com/repos/apache/incubator-airflow/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-airflow/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-airflow/events","assignees_url":"https://api.github.com/repos/apache/incubator-airflow/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-airflow/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-airflow/tags","blobs_url":"https://api.github.com/repos/apache/incubator-airflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-airflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-airflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-airflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-airflow/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-airflow/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-airflow/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-airflow/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-airflow/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-airflow/subscription","commits_url":"https://api.github.com/repos/apache/incubator-airflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-airflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-airflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-airflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-airflow/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-airflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-airflow/merges","archive_url":"https://api.github.com/repos/apache/incubator-airflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-airflow/downloads","issues_url":"https://api.github.com/repos/apache/incubator-airflow/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-airflow/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-airflow/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-airflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-airflow/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-airflow/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-airflow/deployments","created_at":"2015-04-13T18:04:58Z","updated_at":"2016-11-02T03:34:51Z","pushed_at":"2016-11-02T21:01:39Z","git_url":"git://github.com/apache/incubator-airflow.git","ssh_url":"git@github.com:apache/incubator-airflow.git","clone_url":"https://github.com/apache/incubator-airflow.git","svn_url":"https://github.com/apache/incubator-airflow","homepage":"","size":14917,"stargazers_count":3737,"watchers_count":3737,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":907,"mirror_url":null,"open_issues_count":172,"forks":907,"open_issues":172,"watchers":3737,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/1765"},"html":{"href":"https://github.com/apache/incubator-airflow/pull/1765"},"issue":{"href":"https://api.github.com/repos/apache/incubator-airflow/issues/1765"},"comments":{"href":"https://api.github.com/repos/apache/incubator-airflow/issues/1765/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/1765/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/1765/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-airflow/statuses/5320309f9afbbc68b76b3434bec59445be9d3a3d"}}}}
{"actor":{"display_login":"gwax"}}