{"action":"created","comment":{"url":"https://api.github.com/repos/django/django/pulls/comments/36375307","id":36375307,"diff_hunk":"@@ -903,17 +905,102 @@ def __init__(self, *args, **kwargs):\n         self.return_id = False\n         super(SQLInsertCompiler, self).__init__(*args, **kwargs)\n \n-    def placeholder(self, field, val):\n+    def field_as_sql(self, field, val):\n+        \"\"\"\n+        Take a field, and a value intended to be saved on that field, and\n+        return placeholder SQL and accompanying params. Checks for raw values,\n+        expressions and fields with get_placeholder() defined in that order.\n+        \"\"\"\n+\n         if field is None:\n             # A field value of None means the value is raw.\n-            return val\n+            sql, params = val, []\n+\n+        elif hasattr(val, 'as_sql'):\n+            # This is an expression, let's compile it.\n+            sql, params = self.compile(val)\n+\n         elif hasattr(field, 'get_placeholder'):\n             # Some fields (e.g. geo fields) need special munging before\n             # they can be inserted.\n-            return field.get_placeholder(val, self, self.connection)\n+            sql, params = field.get_placeholder(val, self, self.connection), [val]\n+\n         else:\n             # Return the common case for the placeholder\n-            return '%s'\n+            sql, params = '%s', [val]\n+\n+        # The following hook is only used by Oracle Spatial, which sometimes\n+        # needs to yield 'NULL' and [] as its placeholder and params instead\n+        # of '%s' and [None]. The 'NULL' placeholder is produced earlier by\n+        # OracleOperations.get_geom_placeholder(). The following line removes\n+        # the corresponding None parameter. See ticket #10888.\n+        params = self.connection.ops.modify_insert_params(sql, params)\n+\n+        return sql, params\n+\n+    def prepare_value(self, field, value):\n+        \"\"\"\n+        Prepare a value to be used in a query, by resolving it if it is an\n+        expression, and otherwise calling the field's get_db_prep_save().\n+        \"\"\"\n+\n+        def find_fs(expr):","path":"django/db/models/sql/compiler.py","position":58,"original_position":58,"commit_id":"23f93984f784075ec83617f5538d75449ad2f3c1","original_commit_id":"23f93984f784075ec83617f5538d75449ad2f3c1","user":{"login":"jarshwah","id":541083,"avatar_url":"https://avatars.githubusercontent.com/u/541083?v=3","gravatar_id":"","url":"https://api.github.com/users/jarshwah","html_url":"https://github.com/jarshwah","followers_url":"https://api.github.com/users/jarshwah/followers","following_url":"https://api.github.com/users/jarshwah/following{/other_user}","gists_url":"https://api.github.com/users/jarshwah/gists{/gist_id}","starred_url":"https://api.github.com/users/jarshwah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarshwah/subscriptions","organizations_url":"https://api.github.com/users/jarshwah/orgs","repos_url":"https://api.github.com/users/jarshwah/repos","events_url":"https://api.github.com/users/jarshwah/events{/privacy}","received_events_url":"https://api.github.com/users/jarshwah/received_events","type":"User","site_admin":false},"body":"I don't think this is the best way to discover F() expressions. You're probably better off calling `expression.get_source_expressions()` recursively. There are also going to be many other expression types that don't make sense with regard to insertions -- do we need to guard against those too? I would think probably not. \r\n\r\nI guess that `F()` are easy to accidentally insert since most functions accepting strings assume `F(string_value)` rather than `Value(string_value)`. Is that why you've added this check?","created_at":"2015-08-06T01:55:12Z","updated_at":"2015-08-06T01:55:12Z","html_url":"https://github.com/django/django/pull/5099#discussion_r36375307","pull_request_url":"https://api.github.com/repos/django/django/pulls/5099","_links":{"self":{"href":"https://api.github.com/repos/django/django/pulls/comments/36375307"},"html":{"href":"https://github.com/django/django/pull/5099#discussion_r36375307"},"pull_request":{"href":"https://api.github.com/repos/django/django/pulls/5099"}}},"pull_request":{"url":"https://api.github.com/repos/django/django/pulls/5099","id":41533825,"html_url":"https://github.com/django/django/pull/5099","diff_url":"https://github.com/django/django/pull/5099.diff","patch_url":"https://github.com/django/django/pull/5099.patch","issue_url":"https://api.github.com/repos/django/django/issues/5099","number":5099,"state":"open","locked":false,"title":"Fixed #24509 -- Added Expression support to SQLInsertCompiler","user":{"login":"AlexHill","id":1011483,"avatar_url":"https://avatars.githubusercontent.com/u/1011483?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexHill","html_url":"https://github.com/AlexHill","followers_url":"https://api.github.com/users/AlexHill/followers","following_url":"https://api.github.com/users/AlexHill/following{/other_user}","gists_url":"https://api.github.com/users/AlexHill/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexHill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexHill/subscriptions","organizations_url":"https://api.github.com/users/AlexHill/orgs","repos_url":"https://api.github.com/users/AlexHill/repos","events_url":"https://api.github.com/users/AlexHill/events{/privacy}","received_events_url":"https://api.github.com/users/AlexHill/received_events","type":"User","site_admin":false},"body":"Thanks @SmileyChris for help and review at the PyCon sprints!","created_at":"2015-08-04T04:37:55Z","updated_at":"2015-08-06T01:55:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"69542f9dfabc227f4cbddad3c6e95264f9fa8d56","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/django/django/pulls/5099/commits","review_comments_url":"https://api.github.com/repos/django/django/pulls/5099/comments","review_comment_url":"https://api.github.com/repos/django/django/pulls/comments{/number}","comments_url":"https://api.github.com/repos/django/django/issues/5099/comments","statuses_url":"https://api.github.com/repos/django/django/statuses/23f93984f784075ec83617f5538d75449ad2f3c1","head":{"label":"AlexHill:create_expressions","ref":"create_expressions","sha":"23f93984f784075ec83617f5538d75449ad2f3c1","user":{"login":"AlexHill","id":1011483,"avatar_url":"https://avatars.githubusercontent.com/u/1011483?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexHill","html_url":"https://github.com/AlexHill","followers_url":"https://api.github.com/users/AlexHill/followers","following_url":"https://api.github.com/users/AlexHill/following{/other_user}","gists_url":"https://api.github.com/users/AlexHill/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexHill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexHill/subscriptions","organizations_url":"https://api.github.com/users/AlexHill/orgs","repos_url":"https://api.github.com/users/AlexHill/repos","events_url":"https://api.github.com/users/AlexHill/events{/privacy}","received_events_url":"https://api.github.com/users/AlexHill/received_events","type":"User","site_admin":false},"repo":{"id":11269762,"name":"django","full_name":"AlexHill/django","owner":{"login":"AlexHill","id":1011483,"avatar_url":"https://avatars.githubusercontent.com/u/1011483?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexHill","html_url":"https://github.com/AlexHill","followers_url":"https://api.github.com/users/AlexHill/followers","following_url":"https://api.github.com/users/AlexHill/following{/other_user}","gists_url":"https://api.github.com/users/AlexHill/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexHill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexHill/subscriptions","organizations_url":"https://api.github.com/users/AlexHill/orgs","repos_url":"https://api.github.com/users/AlexHill/repos","events_url":"https://api.github.com/users/AlexHill/events{/privacy}","received_events_url":"https://api.github.com/users/AlexHill/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AlexHill/django","description":"The Web framework for perfectionists with deadlines.","fork":true,"url":"https://api.github.com/repos/AlexHill/django","forks_url":"https://api.github.com/repos/AlexHill/django/forks","keys_url":"https://api.github.com/repos/AlexHill/django/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AlexHill/django/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AlexHill/django/teams","hooks_url":"https://api.github.com/repos/AlexHill/django/hooks","issue_events_url":"https://api.github.com/repos/AlexHill/django/issues/events{/number}","events_url":"https://api.github.com/repos/AlexHill/django/events","assignees_url":"https://api.github.com/repos/AlexHill/django/assignees{/user}","branches_url":"https://api.github.com/repos/AlexHill/django/branches{/branch}","tags_url":"https://api.github.com/repos/AlexHill/django/tags","blobs_url":"https://api.github.com/repos/AlexHill/django/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AlexHill/django/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AlexHill/django/git/refs{/sha}","trees_url":"https://api.github.com/repos/AlexHill/django/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AlexHill/django/statuses/{sha}","languages_url":"https://api.github.com/repos/AlexHill/django/languages","stargazers_url":"https://api.github.com/repos/AlexHill/django/stargazers","contributors_url":"https://api.github.com/repos/AlexHill/django/contributors","subscribers_url":"https://api.github.com/repos/AlexHill/django/subscribers","subscription_url":"https://api.github.com/repos/AlexHill/django/subscription","commits_url":"https://api.github.com/repos/AlexHill/django/commits{/sha}","git_commits_url":"https://api.github.com/repos/AlexHill/django/git/commits{/sha}","comments_url":"https://api.github.com/repos/AlexHill/django/comments{/number}","issue_comment_url":"https://api.github.com/repos/AlexHill/django/issues/comments{/number}","contents_url":"https://api.github.com/repos/AlexHill/django/contents/{+path}","compare_url":"https://api.github.com/repos/AlexHill/django/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AlexHill/django/merges","archive_url":"https://api.github.com/repos/AlexHill/django/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AlexHill/django/downloads","issues_url":"https://api.github.com/repos/AlexHill/django/issues{/number}","pulls_url":"https://api.github.com/repos/AlexHill/django/pulls{/number}","milestones_url":"https://api.github.com/repos/AlexHill/django/milestones{/number}","notifications_url":"https://api.github.com/repos/AlexHill/django/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AlexHill/django/labels{/name}","releases_url":"https://api.github.com/repos/AlexHill/django/releases{/id}","created_at":"2013-07-09T01:24:29Z","updated_at":"2015-03-10T00:44:58Z","pushed_at":"2015-08-05T09:18:01Z","git_url":"git://github.com/AlexHill/django.git","ssh_url":"git@github.com:AlexHill/django.git","clone_url":"https://github.com/AlexHill/django.git","svn_url":"https://github.com/AlexHill/django","homepage":"http://www.djangoproject.com/","size":131684,"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":"django:master","ref":"master","sha":"770449e24b3b0fa60d870bc3404961ddca754c3b","user":{"login":"django","id":27804,"avatar_url":"https://avatars.githubusercontent.com/u/27804?v=3","gravatar_id":"","url":"https://api.github.com/users/django","html_url":"https://github.com/django","followers_url":"https://api.github.com/users/django/followers","following_url":"https://api.github.com/users/django/following{/other_user}","gists_url":"https://api.github.com/users/django/gists{/gist_id}","starred_url":"https://api.github.com/users/django/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/django/subscriptions","organizations_url":"https://api.github.com/users/django/orgs","repos_url":"https://api.github.com/users/django/repos","events_url":"https://api.github.com/users/django/events{/privacy}","received_events_url":"https://api.github.com/users/django/received_events","type":"Organization","site_admin":false},"repo":{"id":4164482,"name":"django","full_name":"django/django","owner":{"login":"django","id":27804,"avatar_url":"https://avatars.githubusercontent.com/u/27804?v=3","gravatar_id":"","url":"https://api.github.com/users/django","html_url":"https://github.com/django","followers_url":"https://api.github.com/users/django/followers","following_url":"https://api.github.com/users/django/following{/other_user}","gists_url":"https://api.github.com/users/django/gists{/gist_id}","starred_url":"https://api.github.com/users/django/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/django/subscriptions","organizations_url":"https://api.github.com/users/django/orgs","repos_url":"https://api.github.com/users/django/repos","events_url":"https://api.github.com/users/django/events{/privacy}","received_events_url":"https://api.github.com/users/django/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/django/django","description":"The Web framework for perfectionists with deadlines.","fork":false,"url":"https://api.github.com/repos/django/django","forks_url":"https://api.github.com/repos/django/django/forks","keys_url":"https://api.github.com/repos/django/django/keys{/key_id}","collaborators_url":"https://api.github.com/repos/django/django/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/django/django/teams","hooks_url":"https://api.github.com/repos/django/django/hooks","issue_events_url":"https://api.github.com/repos/django/django/issues/events{/number}","events_url":"https://api.github.com/repos/django/django/events","assignees_url":"https://api.github.com/repos/django/django/assignees{/user}","branches_url":"https://api.github.com/repos/django/django/branches{/branch}","tags_url":"https://api.github.com/repos/django/django/tags","blobs_url":"https://api.github.com/repos/django/django/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/django/django/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/django/django/git/refs{/sha}","trees_url":"https://api.github.com/repos/django/django/git/trees{/sha}","statuses_url":"https://api.github.com/repos/django/django/statuses/{sha}","languages_url":"https://api.github.com/repos/django/django/languages","stargazers_url":"https://api.github.com/repos/django/django/stargazers","contributors_url":"https://api.github.com/repos/django/django/contributors","subscribers_url":"https://api.github.com/repos/django/django/subscribers","subscription_url":"https://api.github.com/repos/django/django/subscription","commits_url":"https://api.github.com/repos/django/django/commits{/sha}","git_commits_url":"https://api.github.com/repos/django/django/git/commits{/sha}","comments_url":"https://api.github.com/repos/django/django/comments{/number}","issue_comment_url":"https://api.github.com/repos/django/django/issues/comments{/number}","contents_url":"https://api.github.com/repos/django/django/contents/{+path}","compare_url":"https://api.github.com/repos/django/django/compare/{base}...{head}","merges_url":"https://api.github.com/repos/django/django/merges","archive_url":"https://api.github.com/repos/django/django/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/django/django/downloads","issues_url":"https://api.github.com/repos/django/django/issues{/number}","pulls_url":"https://api.github.com/repos/django/django/pulls{/number}","milestones_url":"https://api.github.com/repos/django/django/milestones{/number}","notifications_url":"https://api.github.com/repos/django/django/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/django/django/labels{/name}","releases_url":"https://api.github.com/repos/django/django/releases{/id}","created_at":"2012-04-28T02:47:18Z","updated_at":"2015-08-06T01:38:46Z","pushed_at":"2015-08-06T01:25:17Z","git_url":"git://github.com/django/django.git","ssh_url":"git@github.com:django/django.git","clone_url":"https://github.com/django/django.git","svn_url":"https://github.com/django/django","homepage":"https://www.djangoproject.com/","size":302486,"stargazers_count":15410,"watchers_count":15410,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6180,"mirror_url":null,"open_issues_count":69,"forks":6180,"open_issues":69,"watchers":15410,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/django/django/pulls/5099"},"html":{"href":"https://github.com/django/django/pull/5099"},"issue":{"href":"https://api.github.com/repos/django/django/issues/5099"},"comments":{"href":"https://api.github.com/repos/django/django/issues/5099/comments"},"review_comments":{"href":"https://api.github.com/repos/django/django/pulls/5099/comments"},"review_comment":{"href":"https://api.github.com/repos/django/django/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/django/django/pulls/5099/commits"},"statuses":{"href":"https://api.github.com/repos/django/django/statuses/23f93984f784075ec83617f5538d75449ad2f3c1"}}}}