I could not find a way to do that and I think it's an enhancement request.
Would be really nice to have a way to cast between classes. I mean, when you have Person and Employee classes, for example (where Employee is a subclasse of Person), would be great to create an Employee based on a previous saved Person.
Today, if you try to do:
>>> # myPerson = a Person object from database >>> myPerson.__class__ = Employee >>> myPerson.working = True >>> session.save(myPerson) >>> session.flush()
you would get an identity change Exception:
Can't change the identity of instance Employee@-0x4873a7d4 in session (existing identity: (<class '__main__.Person'>, (1,), None); new identity: (<class '__main__.Employee'>, (1,), None))
(see attached script for details)
Would be possible to do something like this?