Re: [sqlalchemy] returned_defaults fails after upgrading from 0.9.4

2015-11-01 Thread gbr
So instead of

).return_defaults()
result = session.execute(qry)
new_id = result.returned_defaults['id']

I write 

 ).returning(table.c.id)
result = session.execute(qry)
new_id = result.fetchone()['id']

and everything works as was? Is there any side-effects to consider?

Best regards and thanks for the help!


On Sunday, 1 November 2015 16:43:27 UTC+11, Michael Bayer wrote:
>
> this is likely 
>
> http://docs.sqlalchemy.org/en/rel_1_0/changelog/migration_10.html#the-insert-from-select-construct-now-implies-inline-true
>  
> - use explicit returning().  returned_defaults implies only a single row 
> INSERT which is not the case for INSERT from SELECT. 
>
>
>
>
> On 11/01/2015 01:29 AM, gbr wrote: 
> > I've just tried to upgrade from 0.9.4 to the latest 1.0.9 version (yes, 
> > I'm late) and am running into some problems. Most notably, 
> > `returned_defaults` from an insert query does not seem to work as 
> > before. This is part of my code: 
> > 
> > new_record = select([user_id, parent_id, 1 + func.max(
> some_table.c.id)]) 
> > qry = insert(revision_table).from_select( 
> > ['user_id', 'parent_id', 'id'], 
> > new_record 
> > ).return_defaults() 
> > result = session.execute(qry) 
> > new_id = result.returned_defaults['id'] 
> > 
> >   File "/python2.7/site-packages/sqlalchemy/engine/result.py", line 822, 
> > in returned_defaults 
> > return self.context.returned_defaults 
> > AttributeError: 'PGExecutionContext_psycopg2' object has no attribute 
> > 'returned_defaults' 
> > 
> > I've also upgraded psycopg2 to the latest, but the issue remains. 
> > `session` is a sqlalchemy.orm.scoping.scoped_session object. 
> > 
> > Hope this information is enough and someone can help. 
> > 
> > Thanks. 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "sqlalchemy" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to sqlalchemy+...@googlegroups.com  
> > . 
> > To post to this group, send email to sqlal...@googlegroups.com 
>  
> > . 
> > Visit this group at http://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] returned_defaults fails after upgrading from 0.9.4

2015-10-31 Thread Mike Bayer
this is likely
http://docs.sqlalchemy.org/en/rel_1_0/changelog/migration_10.html#the-insert-from-select-construct-now-implies-inline-true
- use explicit returning().  returned_defaults implies only a single row
INSERT which is not the case for INSERT from SELECT.




On 11/01/2015 01:29 AM, gbr wrote:
> I've just tried to upgrade from 0.9.4 to the latest 1.0.9 version (yes,
> I'm late) and am running into some problems. Most notably,
> `returned_defaults` from an insert query does not seem to work as
> before. This is part of my code:
> 
> new_record = select([user_id, parent_id, 1 + func.max(some_table.c.id)])
> qry = insert(revision_table).from_select(
> ['user_id', 'parent_id', 'id'],
> new_record
> ).return_defaults()
> result = session.execute(qry)
> new_id = result.returned_defaults['id']
>
>   File "/python2.7/site-packages/sqlalchemy/engine/result.py", line 822,
> in returned_defaults
> return self.context.returned_defaults
> AttributeError: 'PGExecutionContext_psycopg2' object has no attribute
> 'returned_defaults'
> 
> I've also upgraded psycopg2 to the latest, but the issue remains.
> `session` is a sqlalchemy.orm.scoping.scoped_session object.
> 
> Hope this information is enough and someone can help.
> 
> Thanks.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+unsubscr...@googlegroups.com
> .
> To post to this group, send email to sqlalchemy@googlegroups.com
> .
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] returned_defaults fails after upgrading from 0.9.4

2015-10-31 Thread gbr
I've just tried to upgrade from 0.9.4 to the latest 1.0.9 version (yes, I'm 
late) and am running into some problems. Most notably, `returned_defaults` 
from an insert query does not seem to work as before. This is part of my 
code:

new_record = select([user_id, parent_id, 1 + func.max(some_table.c.id)])
qry = insert(revision_table).from_select(
['user_id', 'parent_id', 'id'],
new_record
).return_defaults()
result = session.execute(qry)
new_id = result.returned_defaults['id']

  File "/python2.7/site-packages/sqlalchemy/engine/result.py", line 822, in 
returned_defaults
return self.context.returned_defaults
AttributeError: 'PGExecutionContext_psycopg2' object has no attribute 
'returned_defaults'

I've also upgraded psycopg2 to the latest, but the issue remains. `session` 
is a sqlalchemy.orm.scoping.scoped_session object.

Hope this information is enough and someone can help.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.