title: Potential Django Bug In QuerySet.query?
body: <p>Disclaimer: I'm still learning Django, so I might be missing something here, but I can't see what it would be...</p>
  
  <p>I'm running Python 2.6.1 and Django 1.2.1.</p>
  
  <pre><code>(InteractiveConsole)
  &gt;&gt;&gt; from myproject.myapp.models import *
  &gt;&gt;&gt; qs = Identifier.objects.filter(Q(key="a") | Q(key="b"))
  &gt;&gt;&gt; print qs.query
  SELECT `app_identifier`.`id`, `app_identifier`.`user_id`, 
  `app_identifier`.`key`, `app_identifier`.`value` FROM
  `app_identifier` WHERE (`app_identifier`.`key` = a  OR
  `app_identifier`.`key` = b )
  &gt;&gt;&gt;
  </code></pre>
  
  <p>Notice that it doesn't put quotes around "a" or "b"!  Now, I've determined that the query <i>executes</i> fine.  So, in reality, it must be doing so.  But, it's pretty annoying that printing out the query prints it wrong.  Especially if I did something like this...</p>
  
  <pre><code>&gt;&gt;&gt; qs = Identifier.objects.filter(Q(key=") AND") | Q(key="\"x\"); DROP TABLE      
                  `app_identifier`"))
  &gt;&gt;&gt; print qs.query
  SELECT `app_identifier`.`id`, `app_identifier`.`user_id`,
  `app_identifier`.`key`, `app_identifier`.`value` FROM
  `app_identifier` WHERE (`app_identifier`.`key` = ) AND  OR
  `app_identifier`.`key` = "x"); DROP TABLE `app_identifier` )
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>Which, as you can see, not only creates completely malformed SQL code, but also has the seeds of a SQL injection attack.  Now, obviously this wouldn't actually work, for quite a number of reasons (1. The syntax is all wrong, intentionally, to show the oddity of Django's behavior.  2. Django won't actually execute the query like this, it will actually put quotes and slashes and all that in there like it's supposed to).</p>
  
  <p>But, this really makes debugging confusing, and it makes me wonder if something's gone wrong with my Django installation.</p>
  
  <p>Does this happen for you?  If so/not, what version of Python and Django do you have?</p>
  
  <p>Any thoughts?</p>