有没有办法深度复制包含association_proxy的SQLAlchemy类的对象实例?
深度复制此类的实例时,例如
class Device(Base):
__tablename__ = 'collect_inventory'
_id = Column('id', Integer, primary_key=True)
_ip = Column('ip', String(15), index=True)
fields = association_proxy("field_values", "value",
creator=lambda k, v:
FieldValue(field=k, value=v)
)
我收到此错误:
File "/opt/secadvisor/lib/component.py", line 198, in _deliver_mods
receiver.receive(copy.deepcopy(data), msg_type, module_name, component)
File "/usr/lib64/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.6/copy.py", line 338, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python2.6/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python2.6/copy.py", line 255, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python2.6/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python2.6/copy.py", line 235, in _deepcopy_tuple
y.append(deepcopy(a, memo))
File "/usr/lib64/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.6/copy.py", line 338, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python2.6/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python2.6/copy.py", line 255, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.6/copy.py", line 323, in _reconstruct
y = callable(*args)
File "/usr/lib64/python2.6/copy_reg.py", line 93, in __newobj__
return cls.__new__(cls, *args)
TypeError: attrgetter expected 1 arguments, got 0
仅在访问association_proxy字段时发生错误(在这种情况下为fields
)。