Skip to content

Commit c382fc3

Browse files
committed
Fix position snapshot SystemError on deepcopy
1 parent 2e67e03 commit c382fc3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

RELEASES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ None
7979
- Fixed portfolio handling of `OrderExpired` events not updating state (margin requirements may change)
8080
- Fixed event handling for `ExecutionEngine` so it fully updates the `Portfolio` before to publishing execution events (#2513), thanks for reporting @stastnypremysl
8181
- Fixed position snapshot cache access for `ExecutionEngine`
82+
- Fixed position snapshot `SystemError` calling `copy.deepcopy()` by simply using a `pickle` round trip to copy the position instance
8283
- Fixed event purging edge cases for account and position where at least one event must be guaranteed
8384
- Fixed authentication for Redis when password provided with no username
8485
- Fixed various numpy and pandas FutureWarning(s)

nautilus_trader/cache/cache.pyx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
# -------------------------------------------------------------------------------------------------
1515

16-
import copy
1716
import pickle
1817
import time
1918
import uuid
@@ -2056,11 +2055,11 @@ cdef class Cache(CacheFacade):
20562055
20572056
"""
20582057
cdef PositionId position_id = position.id
2059-
cdef list snapshots = self._position_snapshots.get(position_id)
2058+
cdef list[bytes] snapshots = self._position_snapshots.get(position_id)
20602059

2061-
# Reassign position ID
2062-
cdef Position copied_position = copy.deepcopy(position)
2063-
copied_position.id = PositionId(f"{position.id.to_str()}-{uuid.uuid4()}")
2060+
# Create snapshot with modified position ID
2061+
cdef Position copied_position = pickle.loads(pickle.dumps(position))
2062+
copied_position.id = PositionId(f"{position_id.to_str()}-{uuid.uuid4()}")
20642063
cdef bytes position_pickled = pickle.dumps(copied_position)
20652064

20662065
if snapshots is not None:

0 commit comments

Comments
 (0)