#14019: SQLInsertCompiler.as_sql() failure
------------------------------------------+---------------------------------
 Reporter:  mlavin                        |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Database layer (models, ORM)  |     Version:  1.2       
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 I came across a problem with `SQLInsertCompiler.as_sql` function while
 trying to get a stacktrace printed on insert errors (using
 [http://github.com/dcramer/django-db-log django-db-log]). I found that the
 `as_sql` function has an implicit condition that `execute_sql` must be
 called first because `execute_sql` sets the `return_id` attribute. This
 simple sequence shows the issue using any core db-backend:

 {{{
 from django.contrib.auth.models import User
 from django.db import router
 from django.db.models.sql import InsertQuery

 db = router.db_for_write(User)
 query = InsertQuery(User)
 query.insert_values([(User._meta.fields[0], 1)], raw_values=False)
 print query.get_compiler(using=db).as_sql()
 }}}

 yields

 {{{
 AttributeError: 'SQLInsertCompiler' object has no attribute 'return_id'
 }}}

 I've attached a patch which checks for the existence of the `return_id`
 attribute and defaults to `False` if not found (as is the convention in
 `execute_sql`).

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14019>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to