#10362: Queryset.update throws ProgrammingError when updating inherited fields
------------------------------------------+---------------------------------
 Reporter:  vbmendes                      |       Owner:  nobody    
   Status:  new                           |   Milestone:  1.1       
Component:  Database layer (models, ORM)  |     Version:  SVN       
 Keywords:  queryset batch update         |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 When trying to batch update an inherited field, using queryset.update()
 method, a ProgrammingError is thrown.

 Lets supose I have two models:


 {{{
 class Pessoa(models.Model):
     nome = models.CharField(max_length="255")
     removido = models.BooleanField(default=False,editable=False)

 class PessoaJuridica(Pessoa):
     cnpj =
 models.CharField(verbose_name=u'CNPJ',max_length="50",blank=True)
 }}}


 The error is thrown by this code:

 {{{
 >>> import django
 >>> django.get_version()
 u'1.1 alpha 1 SVN-9905'
 >>> from pessoas.models import Pessoa, PessoaJuridica
 >>> PessoaJuridica.objects.filter(pk__in=[61,]).update(cnpj='123')
 1
 >>> Pessoa.objects.filter(pk__in=[61,]).update(removido=True)
 1
 >>> Pessoa.objects.filter(pk__in=[61,]).update(removido=False)
 1
 >>> PessoaJuridica.objects.filter(pk__in=[61,]).update(removido=True)
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
 450, in update
     rows = query.execute_sql(None)
   File "/usr/lib/python2.5/site-
 packages/django/db/models/sql/subqueries.py", line 119, in execute_sql
     cursor = super(UpdateQuery, self).execute_sql(result_type)
   File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py",
 line 2019, in execute_sql
     sql, params = self.as_sql()
   File "/usr/lib/python2.5/site-
 packages/django/db/models/sql/subqueries.py", line 131, in as_sql
     self.pre_sql_setup()
   File "/usr/lib/python2.5/site-
 packages/django/db/models/sql/subqueries.py", line 201, in pre_sql_setup
     for rows in query.execute_sql(MULTI):
   File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py",
 line 2028, in execute_sql
     cursor.execute(sql, params)
   File "/usr/lib/python2.5/site-packages/django/db/backends/util.py", line
 19, in execute
     return self.cursor.execute(sql, params)
 ProgrammingError: syntax error at or near "WHERE"
 LINE 1: SELECT U1."id" FROM WHERE U0."pessoa_ptr_id" IN (61)
                             ^

 >>>
 }}}

 So, one can notice that the error only occurs with inherited fields.
 'cnpj' is a field of PessoaJuridica and 'removido' is inherited from
 Pessoa. I read the documentation where it says that batch update doesn't
 works with related fields. I know that in this case, in database level,
 'removido' is a related field. But in object level, it isn't. So I expect
 the batch update works in this case, but it doesn't happens.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10362>
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 django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to