Michael Bayer wrote:
> On May 21, 2009, at 2:04 AM, jo wrote:
>
>   
>> Michael Bayer ha scritto:
>>     
>>> that is your own application changing the primary key of a loaded
>>> instance, which is a feature very old versions of SQLAlchemy did not
>>> support.  Upgrade to any recent version of 0.4 or 0.5 and you wont
>>> have that issue anymore.
>>>
>>>       
>> Is there any property in the instance to see its state before  
>> flushing it?
>>     
>
> here are the ways to check for changes, if thats what it is you're  
> looking for.  Most of them will still require that you upgrade from  
> your very old version of SQLAlchemy:
>
> obj in session.dirty
> session.is_modified(obj)
>
> from sqlalchemy.orm import attributes
> history = attributes.get_history(obj, attrname)
>
>   
I see, Michael, you are right, I need to upgrade my SQLAlchemy version.

In the meanwhile I did a last try, to trap the FlushError exception.

raise exceptions.FlushError("Can't change the identity of instance %s in 
session (existing identity: %s; new identity: %s)" % 
(mapperutil.instance_str(obj), obj._instance_key, instance_key))
FlushError: Can't change the identity of instance spe...@0x9f4b9ac in session 
(existing identity: (<class 'sicer.BASE.model.tabelleCodifica.specie.Specie'>, 
(u'0141',), None); new identity: (<class 
'sicer.BASE.model.tabelleCodifica.specie.Specie'>, (u'08',), None))


in this way:

from sqlalchemy.exceptions import FlushError
try:
     session.flush()
except FlushError:
     session.expunge(obj)

... but, it seems an error from TG. What exactly do session.expunge ?

Page handler: <bound method Controller.save of 
<sicer.BASE.controller.tabelleCodifica.specie.Controller instance at 
0x9e9f30c>>

Traceback (most recent call last):
  File "/var/lib/python-support/python2.4/cherrypy/_cphttptools.py", line 105, 
in _run
    self.main()
  File "/var/lib/python-support/python2.4/cherrypy/_cphttptools.py", line 254, 
in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in save
  File 
"/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/identity/conditions.py",
 line 235, in require
    return fn(self, *args, **kwargs)
  File "<string>", line 3, in save
  File 
"/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/controllers.py",
 line 342, in expose
    output = database.run_with_transaction(
  File "<string>", line 5, in run_with_transaction
  File 
"/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/database.py",
 line 362, in sa_rwt
    retval = dispatch_exception(e,args,kw)
  File 
"/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/database.py",
 line 360, in sa_rwt
    req.sa_transaction.commit()
  File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py", line 73, 
in commit
    t[1].commit()
  File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 670, 
in commit
    raise exceptions.InvalidRequestError("This transaction is inactive")
InvalidRequestError: This transaction is inactive


j


--~--~---------~--~----~------------~-------~--~----~
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