Setting the instance key works fine. Thanks!
Bye,
Kevin
Michael Bayer wrote:
>
> On Oct 24, 2007, at 12:17 PM, Kevin Schmidt wrote:
>
>> Hello all,
>>
>> I have a problem using session.merge() in version 0.3.10. I'm
>> trying to merge an
>> object I'm getting via SOAP from a different server. Here is my code:
>>
>>
>> self._censusTable = Table('census', self._dbMetaData, autoload=True)
>> self._censusMapper = mapper(Census, self._censusTable)
>> self._session = create_session()
>>
>>
>> def writeCensus(self, soapCensus):
>> currentTrans = self._session.create_transaction()
>> try:
>> sessionCensus = \
>> self._session.query(Census).get(soapCensus.id)
>> test = self._session.merge(soapCensus)
>> currentTrans.commit()
>>
>> except Exception, e:
>> currentTrans.rollback()
>>
>>
>> The result is:
>>
>> FlushError: New instance [EMAIL PROTECTED] with identity key (<class
>> 'census.Census'>, (12347,), None) conflicts with persistent instance
>> [EMAIL PROTECTED]
>>
>> soapCensus is an instance of class Census created by the SOAP
>> library (ZSI),
>> which should be the same as restoring an object via pickle.
>> Am I doing something wrong? Do I have to use 0.4 for this to work?
>> Help would be appreciated.
>
> the soapCensus you're restoring does not have an _instance_key
> attribute on it, so the merge() thinks its a pending instance (i.e.
> has never been stored in the DB before), and adds it separately to
> the session without affecting the current instance already in the
> session. when the flush occurs, it conflicts with the existing
> instance already in the session. so youd need to stick an
> _instance_key on it before merging, which you can do via
> soapCensus._instance_key = Session.identity_key(instance=soapCensus).
>
> since people are starting to use merge() now, and consequently
> tripping over its awkwardness, it seems like the method is going to
> need more attention since I will grant that it probably should be
> figuring out that the instance has a primary key on it already. i
> added ticket 830 for this.
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---