我得到一个dblalchemy对象的db记录,我需要在一些计算过程中查阅原始值,所以我需要原始记录直到结束。但是,当前代码会修改对象,我不想在此时重构太多。
如何制作原始数据的副本?正如预期的那样,deepcopy
似乎会产生问题。我绝对不希望手动复制所有字段,因为在修改db对象时有人会忘记更新此代码。
答案 0 :(得分:0)
你可以在这里复制你的对象有很多选择。我能想到的其中两个是:
final protected def handleFailure(f: Failed): Unit = {
// ¡¡¡ currentMessage.message is the one that cause the exception !!!
currentMessage = Envelope(f, f.child, system)
getChildByRef(f.child) match {
/*
* only act upon the failure, if it comes from a currently known child;
* the UID protects against reception of a Failed from a child which was
* killed in preRestart and re-created in postRestart
*/
case Some(stats) if stats.uid == f.uid ⇒
// ¡¡¡ currentMessage.message is not passed to the handleFailure !!!
if (!actor.supervisorStrategy.handleFailure(this, f.child, f.cause, stats, getAllChildStats)) throw f.cause
case Some(stats) ⇒
publish(Debug(self.path.toString, clazz(actor),
"dropping Failed(" + f.cause + ") from old child " + f.child + " (uid=" + stats.uid + " != " + f.uid + ")"))
case None ⇒
publish(Debug(self.path.toString, clazz(actor), "dropping Failed(" + f.cause + ") from unknown child " + f.child))
}
}
它将提供原始sqlalchemy对象的字典,您可以使用__dict__
函数迭代所有属性,这将提供所有属性。.keys()
模块和inspect
来获取定义的所有属性,并使用getmembers()
方法设置所需的属性。