Yes, my research suggests specifically that it's likely you have 
"autoincrement=False" on the Column in question, or that you aren't using an 
Integer type - such as String or Float, on the primary key column in question.  
 The error below corresponds to when the sequence fires normally, the row is 
inserted successfully, but SQLAlchemy doesn't know to get at the primary key 
value and doesn't have the opportunity to use RETURNING, which would be why the 
behavior changes on PG 7 vs. 8.4.   So basically exactly what the error message 
says is what you should be checking (specifically, that "the mapped Column 
object is configured to expect these generated values").   I also get a failure 
in 0.6 but of a different nature so its possible you have more of a silent 
failure situation going on in 0.6 (which may end up causing no symptoms), if 
that's the version you're using.


On Sep 3, 2011, at 9:13 PM, Michael Bayer wrote:

> additional q:
> 
> 1. upgrading to 0.7 from....0.6 ?  0.5 ?   0.6 was where a major change to 
> "autoincrement" behavior was made re: postgresql
> 2. Any difference in psycopg2 version on prod server vs. dev ?
> 
> On Sep 3, 2011, at 6:07 PM, Michael Bayer wrote:
> 
>> 1. How is the Table metadata defined here (reflection? Or Integer primary 
>> key autoincrement left at its default value of True?) Exact code would be 
>> helpful here if you're not sure.
>> 2. What does the SQL echo output say?  You should see a SELECT that is 
>> specific to the sequence on the table in order to get at a new primary key 
>> value (since pg 7 doesn't support RETURNING) and you'd then see the new 
>> value present in the subsequent INSERT statement's parameter list.  Again 
>> exact, verbatim output can tell us if you want us to take a look.
>> 
>> Sent from my iPhone
>> 
>> On Sep 3, 2011, at 1:06 PM, robert rottermann <rob...@redcor.ch> wrote:
>> 
>>> Hi there,
>>> after Upgrading sqlalchemy to V 0.7.x i get the following error
>>> 
>>> Traceback (innermost last):
>>> Module ZPublisher.Publish, line 126, in publish
>>> Module ZPublisher.mapply, line 77, in mapply
>>> Module ZPublisher.Publish, line 46, in call_object
>>> Module <wrapper>, line 5, in wrapper
>>> Module kss.core.actionwrapper, line 236, in apply
>>> Module ruagaero.intradevcontent.browser.kontaktperson, line 178, in 
>>> kundenListSaveKontaktperson
>>> Module ruagaero.intradevcontent.browser.kontaktperson, line 105, in getFlags
>>> Module ruagaero.intradevcontent.content.flag, line 53, in findFlags
>>> Module sqlalchemy.orm.query, line 1729, in all
>>> Module sqlalchemy.orm.query, line 1838, in __iter__
>>> Module sqlalchemy.orm.session, line 921, in _autoflush
>>> Module sqlalchemy.orm.session, line 1493, in flush
>>> Module sqlalchemy.orm.session, line 1566, in _flush
>>> Module sqlalchemy.orm.unitofwork, line 343, in finalize_flush_changes
>>> Module sqlalchemy.orm.session, line 1117, in _register_newly_persistent
>>> FlushError: Instance <kontaktCL at 0xb2033cc> has a NULL identity key.  If 
>>> this is an auto-generated value, check that the database table allows 
>>> generation of new primary key values, and that the mapped Column object is 
>>> configured to expect these generated values.  Ensure also that this flush() 
>>> is not occurring at an inappropriate time, such as within a load() event.
>>> 
>>> kontaktCL has an "autoincrement" sequence defined as follows:
>>> ALTER TABLE kontakt ALTER COLUMN konid SET DEFAULT 
>>> nextval(('kontakt_konid_seq'::text)::regclass);
>>> 
>>> up to now this sequence was somehow managed by sqlalchemy.
>>> 
>>> The only thing I do create a new record is:
>>> 
>>> kontaktperson = kontaktpersonCL()
>>> for k,v in values.items():
>>>  setattr(kontaktperson, k, v)
>>> session.add(kontaktperson)
>>> session.commit()
>>> 
>>> on my development box this works well (postgres 8.4). However on the live 
>>> database (which is postgres 7.x) I get the error mentioned above.
>>> 
>>> Is there some flag I can set, so sa behaves as it did before?
>>> 
>>> thanks
>>> robert
>>> 
>>> -- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "sqlalchemy" group.
>>> To post to this group, send email to sqlalchemy@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> sqlalchemy+unsubscr...@googlegroups.com.
>>> For more options, visit this group at 
>>> http://groups.google.com/group/sqlalchemy?hl=en.
>>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> sqlalchemy+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/sqlalchemy?hl=en.
>> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

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

Reply via email to