{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments/63594114","id":63594114,"diff_hunk":"@@ -3073,6 +3074,53 @@ def cli(self):\n         args = parser.parse_args()\n         args.func(args, self)\n \n+    @provide_session\n+    def create_dagrun(self,\n+                      run_id,\n+                      execution_date,\n+                      state,\n+                      start_date=None,\n+                      external_trigger=False,\n+                      conf=None,\n+                      session=None):\n+        \"\"\"\n+        Creates a dag run from this dag including the tasks associated with this dag. Returns the dag\n+        run.\n+        :param run_id: defines the the run id for this dag run\n+        :type run_id: string\n+        :param execution_date: the execution date of this dag run\n+        :type execution_date: datetime\n+        :param start_date: the date this dag run should be evaluated\n+        :type state_date: datetime\n+        :param state: the state of the dag run\n+        :type state: State\n+        :param external_trigger: whether this dag run is externally triggered\n+        :type external_trigger: bool\n+        \"\"\"\n+        run = DagRun(\n+            dag_id=self.dag_id,\n+            run_id=run_id,\n+            execution_date=execution_date,\n+            start_date=start_date,\n+            external_trigger=external_trigger,\n+            conf=conf,\n+            state=state\n+        )\n+        session.add(run)\n+\n+        for task in self.tasks:\n+            # todo: check this\n+            if task.adhoc:\n+                continue\n+\n+            ti = TaskInstance(task, execution_date)\n+            session.add(ti)\n+\n+        session.commit()\n+\n+        run.refresh_from_db()","path":"airflow/models.py","position":58,"original_position":58,"commit_id":"80e0120021a7990f905088bba571ecb31b3b5ddf","original_commit_id":"80e0120021a7990f905088bba571ecb31b3b5ddf","user":{"login":"aoen","id":1592778,"avatar_url":"https://avatars.githubusercontent.com/u/1592778?v=3","gravatar_id":"","url":"https://api.github.com/users/aoen","html_url":"https://github.com/aoen","followers_url":"https://api.github.com/users/aoen/followers","following_url":"https://api.github.com/users/aoen/following{/other_user}","gists_url":"https://api.github.com/users/aoen/gists{/gist_id}","starred_url":"https://api.github.com/users/aoen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aoen/subscriptions","organizations_url":"https://api.github.com/users/aoen/orgs","repos_url":"https://api.github.com/users/aoen/repos","events_url":"https://api.github.com/users/aoen/events{/privacy}","received_events_url":"https://api.github.com/users/aoen/received_events","type":"User","site_admin":false},"body":"What's the purpose of this (and maybe consider adding a comment in the code too with your answer)?","created_at":"2016-05-17T20:09:26Z","updated_at":"2016-05-17T20:09:26Z","html_url":"https://github.com/apache/incubator-airflow/pull/1506#discussion_r63594114","pull_request_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/1506","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments/63594114"},"html":{"href":"https://github.com/apache/incubator-airflow/pull/1506#discussion_r63594114"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/1506"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-airflow/pulls/1506","id":70315419,"html_url":"https://github.com/apache/incubator-airflow/pull/1506","diff_url":"https://github.com/apache/incubator-airflow/pull/1506.diff","patch_url":"https://github.com/apache/incubator-airflow/pull/1506.patch","issue_url":"https://api.github.com/repos/apache/incubator-airflow/issues/1506","number":1506,"state":"open","locked":false,"title":"AIRFLOW-124 Implement create_dagrun","user":{"login":"bolkedebruin","id":4282712,"avatar_url":"https://avatars.githubusercontent.com/u/4282712?v=3","gravatar_id":"","url":"https://api.github.com/users/bolkedebruin","html_url":"https://github.com/bolkedebruin","followers_url":"https://api.github.com/users/bolkedebruin/followers","following_url":"https://api.github.com/users/bolkedebruin/following{/other_user}","gists_url":"https://api.github.com/users/bolkedebruin/gists{/gist_id}","starred_url":"https://api.github.com/users/bolkedebruin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolkedebruin/subscriptions","organizations_url":"https://api.github.com/users/bolkedebruin/orgs","repos_url":"https://api.github.com/users/bolkedebruin/repos","events_url":"https://api.github.com/users/bolkedebruin/events{/privacy}","received_events_url":"https://api.github.com/users/bolkedebruin/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- AIRFLOW-124\r\n\r\nThis PR forms the basis for the roadmap (https://drive.google.com/open?id=0B_Y7S4YFVWvYM1o0aDhKMjJhNzg) . It is one of the initial commits from https://github.com/apache/incubator-airflow/compare/master...bolkedebruin:AIRFLOW_SCHEDULER .\r\n \r\n**DAG.create_dagrun (please review: @aoen, @jlowin, @mistercrunch, @artwr )**\r\n\r\nThis creates dagrun from a Dag. It also creates the TaskInstances from the tasks known at instantiation time. By having taskinstances created at dagrun instantiation time, deadlocks that were tested for will not take place anymore (@jlowin, correct? different test required?). For now, the visual consequence of having these taskinstances already there is that they will be black in the tree view.\r\n\r\nTests in core.py were adjusted as they were supposedly creating a dagrun with tasks, while they were actually creating dagruns and orphaned TaskInstances (ie. the dag_id was not matching the dag_id from the dagrun). This was discussed with @artwr, who said these were remnants from the past.\r\n\r\nBy doing this I also fixed an issue in models.py that a dag was not set for a task if called from dag.add_task (@aoen, @jlowin).\r\n\r\n**DagRun.find is a convenience function that returns the DagRuns for a given dag. It makes sure to have a single place how to find dagruns**\r\n\r\nDagRun.find does not work for all cases yet (ie multiple execution dates etc). My aim is to limit the ORM required in sub functions that implement somethings just a bit differently creating compatibility issues.","created_at":"2016-05-17T08:10:34Z","updated_at":"2016-05-17T20:09:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0c4cd717f68bd2cab64e6975d1a28c7bafcce773","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/1506/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/1506/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/1506/comments","statuses_url":"https://api.github.com/repos/apache/incubator-airflow/statuses/80e0120021a7990f905088bba571ecb31b3b5ddf","head":{"label":"bolkedebruin:dag_run","ref":"dag_run","sha":"80e0120021a7990f905088bba571ecb31b3b5ddf","user":{"login":"bolkedebruin","id":4282712,"avatar_url":"https://avatars.githubusercontent.com/u/4282712?v=3","gravatar_id":"","url":"https://api.github.com/users/bolkedebruin","html_url":"https://github.com/bolkedebruin","followers_url":"https://api.github.com/users/bolkedebruin/followers","following_url":"https://api.github.com/users/bolkedebruin/following{/other_user}","gists_url":"https://api.github.com/users/bolkedebruin/gists{/gist_id}","starred_url":"https://api.github.com/users/bolkedebruin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolkedebruin/subscriptions","organizations_url":"https://api.github.com/users/bolkedebruin/orgs","repos_url":"https://api.github.com/users/bolkedebruin/repos","events_url":"https://api.github.com/users/bolkedebruin/events{/privacy}","received_events_url":"https://api.github.com/users/bolkedebruin/received_events","type":"User","site_admin":false},"repo":{"id":38505714,"name":"airflow","full_name":"bolkedebruin/airflow","owner":{"login":"bolkedebruin","id":4282712,"avatar_url":"https://avatars.githubusercontent.com/u/4282712?v=3","gravatar_id":"","url":"https://api.github.com/users/bolkedebruin","html_url":"https://github.com/bolkedebruin","followers_url":"https://api.github.com/users/bolkedebruin/followers","following_url":"https://api.github.com/users/bolkedebruin/following{/other_user}","gists_url":"https://api.github.com/users/bolkedebruin/gists{/gist_id}","starred_url":"https://api.github.com/users/bolkedebruin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolkedebruin/subscriptions","organizations_url":"https://api.github.com/users/bolkedebruin/orgs","repos_url":"https://api.github.com/users/bolkedebruin/repos","events_url":"https://api.github.com/users/bolkedebruin/events{/privacy}","received_events_url":"https://api.github.com/users/bolkedebruin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bolkedebruin/airflow","description":"AirFlow is a system to programmatically author, schedule and monitor data pipelines.","fork":true,"url":"https://api.github.com/repos/bolkedebruin/airflow","forks_url":"https://api.github.com/repos/bolkedebruin/airflow/forks","keys_url":"https://api.github.com/repos/bolkedebruin/airflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bolkedebruin/airflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bolkedebruin/airflow/teams","hooks_url":"https://api.github.com/repos/bolkedebruin/airflow/hooks","issue_events_url":"https://api.github.com/repos/bolkedebruin/airflow/issues/events{/number}","events_url":"https://api.github.com/repos/bolkedebruin/airflow/events","assignees_url":"https://api.github.com/repos/bolkedebruin/airflow/assignees{/user}","branches_url":"https://api.github.com/repos/bolkedebruin/airflow/branches{/branch}","tags_url":"https://api.github.com/repos/bolkedebruin/airflow/tags","blobs_url":"https://api.github.com/repos/bolkedebruin/airflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bolkedebruin/airflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bolkedebruin/airflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/bolkedebruin/airflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bolkedebruin/airflow/statuses/{sha}","languages_url":"https://api.github.com/repos/bolkedebruin/airflow/languages","stargazers_url":"https://api.github.com/repos/bolkedebruin/airflow/stargazers","contributors_url":"https://api.github.com/repos/bolkedebruin/airflow/contributors","subscribers_url":"https://api.github.com/repos/bolkedebruin/airflow/subscribers","subscription_url":"https://api.github.com/repos/bolkedebruin/airflow/subscription","commits_url":"https://api.github.com/repos/bolkedebruin/airflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/bolkedebruin/airflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/bolkedebruin/airflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/bolkedebruin/airflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/bolkedebruin/airflow/contents/{+path}","compare_url":"https://api.github.com/repos/bolkedebruin/airflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bolkedebruin/airflow/merges","archive_url":"https://api.github.com/repos/bolkedebruin/airflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bolkedebruin/airflow/downloads","issues_url":"https://api.github.com/repos/bolkedebruin/airflow/issues{/number}","pulls_url":"https://api.github.com/repos/bolkedebruin/airflow/pulls{/number}","milestones_url":"https://api.github.com/repos/bolkedebruin/airflow/milestones{/number}","notifications_url":"https://api.github.com/repos/bolkedebruin/airflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bolkedebruin/airflow/labels{/name}","releases_url":"https://api.github.com/repos/bolkedebruin/airflow/releases{/id}","deployments_url":"https://api.github.com/repos/bolkedebruin/airflow/deployments","created_at":"2015-07-03T18:27:44Z","updated_at":"2016-04-12T09:44:47Z","pushed_at":"2016-05-17T07:58:26Z","git_url":"git://github.com/bolkedebruin/airflow.git","ssh_url":"git@github.com:bolkedebruin/airflow.git","clone_url":"https://github.com/bolkedebruin/airflow.git","svn_url":"https://github.com/bolkedebruin/airflow","homepage":null,"size":8656,"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":"apache:master","ref":"master","sha":"6f4696ba2ef18d74be8c18080b8ea7b9419608fb","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-05-17T19:34:54Z","pushed_at":"2016-05-17T18:26:58Z","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":12073,"stargazers_count":2735,"watchers_count":2735,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":579,"mirror_url":null,"open_issues_count":173,"forks":579,"open_issues":173,"watchers":2735,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/1506"},"html":{"href":"https://github.com/apache/incubator-airflow/pull/1506"},"issue":{"href":"https://api.github.com/repos/apache/incubator-airflow/issues/1506"},"comments":{"href":"https://api.github.com/repos/apache/incubator-airflow/issues/1506/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/1506/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/1506/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-airflow/statuses/80e0120021a7990f905088bba571ecb31b3b5ddf"}}}}