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
この場合) にアクセスするときにのみ発生します。