[sqlalchemy] Flush error during session.merge()

2007-10-24 Thread Kevin Schmidt

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.

Thanks,
Kevin







--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Flush error during session.merge()

2007-10-24 Thread Kevin Schmidt

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 sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Problem with clear_mapper

2007-04-27 Thread Kevin Schmidt

 I can use clear_mappers() because I use mod_python and my mappers
 are defined
 during init. Is there any other way I can get this select mapped to
 my object?

 non_primary=True  (see the docs on mutliple mappers for a class)
 But that would mean I would define a new non_primary mapper every  
 time,
 wouldn't it? Is this really a good idea for a server software?
 Is there maybe a way to update the used table without redefining  
 the mapper?

 
 if you are creating all kinds of select() objects from which you want  
 to load instances, simply feed those into query.select() and the  
 appropriate instances will be returned (or use query.instances()   
 with the result of execute()).

Thanks, that worked great.

Bye,
Kevin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Problem with clear_mapper

2007-04-26 Thread Kevin Schmidt

The stack before is all my classes, so the last one before is the call to 
class_mapper in the code I send. I had a brief look at the code:

def clear_mapper(m):
del mapper_registry[m.class_key]
attribute_manager.reset_class_managed(m.class_)
if hasattr(m.class_, 'c'):
del m.class_.c
m.class_key.dispose()

The traceback comme form del m.class_.c. It looks to me as it tries to delete 
the columns from the class and fails. I didn't define a mapper without an 
entity_name, could that be the problem?

I can use clear_mappers() because I use mod_python and my mappers are defined
during init. Is there any other way I can get this select mapped to my object?

Bye,
Kevin



Michael Bayer wrote:
 
 On Apr 25, 2007, at 6:06 PM, Kevin Schmidt wrote:
 
  
 clear_mapper(customMapper)


 Running that I get:

 Processing Failure
 c
 /usr/lib/python2.5/site-packages/sqlalchemy/orm/__init__.py: 
 110:clear_mapper]


 
 im not sure what that error means, or if thats a full stack trace (if  
 not, a full stack would be helpful).  but the clear_mapper() function  
 is going to be generally pretty unreliable since the mapper can be  
 involved in relationships with other mappers. (favor clear_mappers() )


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Problem with clear_mapper

2007-04-26 Thread Kevin Schmidt

 I can use clear_mappers() because I use mod_python and my mappers  
 are defined
 during init. Is there any other way I can get this select mapped to  
 my object?

 
 non_primary=True  (see the docs on mutliple mappers for a class)

But that would mean I would define a new non_primary mapper every time,
wouldn't it? Is this really a good idea for a server software?
Is there maybe a way to update the used table without redefining the mapper?

Bye,
Kevin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Problem with clear_mapper

2007-04-25 Thread Kevin Schmidt

Hi everyone,

I have a problem using the following code (with sqlalchemy 0.3.6 and python2.5):


mapperA = mapper(MyClass, self.tables['report_ia'], entity_name = 'REPIA', 
primary_key=[self.tables['report_ia'].c.id])

mapperB = mapper(MyClass, self.tables['report_ib'], entity_name = 'REPIB', 
primary_key=[self.tables['report_ib'].c.id])


customSelect = select(
[
mapperA.c.id,
mapperA.c.uid,
func.count(mapperA.c.itemcount).label(itemcount),
],
mapperA.c.owner.in_( 'User' ) ),
group_by=[mapperA.c.uid, mapperA.c.id]
).alias(totals)

customMapper = mapper(MyClass,
customSelect,
entity_name = temporary,
primary_key = [ customSelect.c.id ],
)

result = self.session.query(customMapper).select()

clear_mapper(customMapper)


Running that I get:

Processing Failure
c
/usr/lib/python2.5/site-packages/sqlalchemy/orm/__init__.py:110:clear_mapper]


What am I doing wrong here?
Any help would be appreciated.

Thanks,
Kevin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---