The problem seems to be that INSERT INTO partitioned_table values(...)
RETURNING ID isn't for some reason returning the ID. Can you confirm
this is the case by running the insert query manually from dbshell?

I believe 1.3 used SELECT
currval(pg_get_serial_sequence('partitioned_table', 'id')) instead of
RETURNING ID. So, that might explain this issue. You could try to set
connection.features.can_return_id_from_insert to False just before
executing any insert query into this table (most conveniently done by
overriding the model's save() method). This is an ugly hack, but it
might make your code work in 1.4...

 - Anssi

On Apr 17, 3:42 pm, Michaël Journo <michael.jou...@whalestreet.com>
wrote:
> Hello,
>
> I use postgresql 9.1 with postgresql_psycopg2 on debian (actually this
> also happens on my mac). I recently moved to django 1.4 and I got this
> error while creating a simple object :
> o = Object()
> o.fieldA = ..
> ....
> o.save()
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/django/db/models/base.py", line 463, in
> save
>     self.save_base(using=using, force_insert=force_insert,
> force_update=force_update)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/django/db/models/base.py", line 551, in
> save_base
>     result = manager._insert([self], fields=fields,
> return_id=update_pk, using=using, raw=raw)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/django/db/models/manager.py", line 203, in
> _insert
>     return insert_query(self.model, objs, fields, **kwargs)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/django/db/models/query.py", line 1576, in
> insert_query
>     return query.get_compiler(using=using).execute_sql(return_id)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/django/db/models/sql/compiler.py", line
> 914, in execute_sql
>     return self.connection.ops.fetch_returned_insert_id(cursor)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/django/db/backends/__init__.py", line 529,
> in fetch_returned_insert_id
>     return cursor.fetchone()[0]
> TypeError: 'NoneType' object is unsubscriptable
>
> My postgresql table for object is a partioned one, based on a trigger
> on insert that look for the right child table. I have a hard time
> finding information about this, except one post 
> herehttp://postgresql.1045698.n5.nabble.com/INSERT-INTO-RETURNING-with-pa...
> suggesting to use rule instead of triggers for handling insert
> returning clause (and it seems it really can handle only ONE returning
> clause, i.e. return object.id).
>
> And in any way, what I really don't understand is that everything
> worked just fine in django 1.3.
>
> I don't know this is a real issue or me handling table partitioning
> the wrong way.
>
> Thank you for your help.

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

Reply via email to