Skip to content

Commit

Permalink
fix(robot-server): Pin pickle protocol version to v4 (#13466)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring authored Sep 6, 2023
1 parent 238d13f commit 816eaa7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 3 additions & 2 deletions robot-server/robot_server/persistence/_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sqlalchemy

from . import legacy_pickle
from .pickle_protocol_version import PICKLE_PROTOCOL_VERSION
from ._utc_datetime import UTCDateTime

_metadata = sqlalchemy.MetaData()
Expand Down Expand Up @@ -94,13 +95,13 @@
# column added in schema v1
sqlalchemy.Column(
"state_summary",
sqlalchemy.PickleType(pickler=legacy_pickle),
sqlalchemy.PickleType(pickler=legacy_pickle, protocol=PICKLE_PROTOCOL_VERSION),
nullable=True,
),
# column added in schema v1
sqlalchemy.Column(
"commands",
sqlalchemy.PickleType(pickler=legacy_pickle),
sqlalchemy.PickleType(pickler=legacy_pickle, protocol=PICKLE_PROTOCOL_VERSION),
nullable=True,
),
# column added in schema v1
Expand Down
23 changes: 23 additions & 0 deletions robot-server/robot_server/persistence/pickle_protocol_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# noqa: D100


from typing_extensions import Final


PICKLE_PROTOCOL_VERSION: Final = 4
"""The version of Python's pickle protocol that we should use for serializing new objects.
We set this to v4 because it's the least common denominator between all of our environments.
At the time of writing (2023-09-05):
* Flex: Python 3.8, pickle protocol v5 by default
* OT-2: Python 3.7, pickle protocol v4 by default
* Typical local dev environments: Python 3.7, pickle protocol v4 by default
For troubleshooting, we want our dev environments be able to read pickles created by any robot.
"""


# TODO(mm, 2023-09-05): Delete this when robot-server stops pickling new objects
# (https://opentrons.atlassian.net/browse/RSS-98), or when we upgrade the Python version
# in our dev environments.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from robot_server.persistence import analysis_table, sqlite_rowid
from robot_server.persistence import legacy_pickle
from robot_server.persistence.pickle_protocol_version import PICKLE_PROTOCOL_VERSION

from .analysis_models import CompletedAnalysis
from .analysis_memcache import MemoryCache
Expand Down Expand Up @@ -289,7 +290,9 @@ async def add(self, completed_analysis_resource: CompletedAnalysisResource) -> N
def _serialize_completed_analysis_to_pickle(
completed_analysis: CompletedAnalysis,
) -> bytes:
return legacy_pickle.dumps(completed_analysis.dict())
return legacy_pickle.dumps(
completed_analysis.dict(), protocol=PICKLE_PROTOCOL_VERSION
)


def _serialize_completed_analysis_to_json(completed_analysis: CompletedAnalysis) -> str:
Expand Down

0 comments on commit 816eaa7

Please sign in to comment.