Здравствуйте, уважаемые краеведы)
Использую в своем проекте sqlalchemy.
возникла необходимость копирования объектов данных возвращаемых sqlalchemy без использования __init__
делаю так:
table_a = Table('table_a', metadata, Column('id', Integer, primary_key=True))
mapper(dbTableA, table_a)
class dbTableA(object):
def _dublicate(self):
obj = self.__class__.__new__(self.__class__)
obj._sa_instance_state = self._sa_instance_state
return obj
если нам sqlalchemy вернёт из БД строчку типа a = dbTableA, и затем сделать b = a._dublicate(), то session.flush() люто ругается
session.flush()
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/session.py, Line 1354, in flush
self._flush(objects)
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/session.py, Line 1432, in _flush
flush_context.execute()
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/unitofwork.py, Line 253, in execute
if up.preexecute(self):
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/unitofwork.py, Line 710, in preexecute
self.processor.preprocess_dependencies(self.targettask, elements, trans, delete=False)
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/dependency.py, Line 254, in preprocess_dependencies
history = uowcommit.get_attribute_history(state, self.key, passive=True)
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/unitofwork.py, Line 117, in get_attribute_history
history = attributes.get_state_history(state, key, passive=passive)
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/attributes.py, Line 1319, in get_state_history
return state.get_history(key, **kwargs)
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/state.py, Line 89, in get_history
return self.manager.get_impl(key).get_history(self, self.dict, **kwargs)
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/attributes.py, Line 656, in get_history
return History.from_attribute(self, state, current)
File /usr/lib/pymodules/python2.6/sqlalchemy/orm/attributes.py, Line 1277, in from_attribute
[x for x in current if x not in original_set],
TypeError: 'NoneType' object is not iterable
собственно как это делать правильно?