diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2019-08-26 20:50:56 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2019-08-26 20:50:56 +0000 |
| commit | 5bf264ca08b8bb38d50baeb48fe1729da4164711 (patch) | |
| tree | 01d09604fbf25dc720376bea00ab8c929c55e6e7 /lib/sqlalchemy | |
| parent | 23ea7265c97d397ca85c7799355277648416e0c6 (diff) | |
| parent | cd2ccee9d807eb601db2d242ce4cdfa8acb98111 (diff) | |
| download | sqlalchemy-5bf264ca08b8bb38d50baeb48fe1729da4164711.tar.gz | |
Merge "Serialize the context dictionary in Load objects"
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/path_registry.py | 38 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/strategy_options.py | 4 |
2 files changed, 36 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/path_registry.py b/lib/sqlalchemy/orm/path_registry.py index 4803dbecb..2f680a3a1 100644 --- a/lib/sqlalchemy/orm/path_registry.py +++ b/lib/sqlalchemy/orm/path_registry.py @@ -100,8 +100,8 @@ class PathRegistry(object): def __reduce__(self): return _unreduce_path, (self.serialize(),) - def serialize(self): - path = self.path + @classmethod + def _serialize_path(cls, path): return list( zip( [m.class_ for m in [path[i] for i in range(0, len(path), 2)]], @@ -110,10 +110,7 @@ class PathRegistry(object): ) @classmethod - def deserialize(cls, path): - if path is None: - return None - + def _deserialize_path(cls, path): p = tuple( chain( *[ @@ -129,6 +126,35 @@ class PathRegistry(object): ) if p and p[-1] is None: p = p[0:-1] + return p + + @classmethod + def serialize_context_dict(cls, dict_, tokens): + return [ + ((key, cls._serialize_path(path)), value) + for (key, path), value in [ + (k, v) + for k, v in dict_.items() + if isinstance(k, tuple) and k[0] in tokens + ] + ] + + @classmethod + def deserialize_context_dict(cls, serialized): + return util.OrderedDict( + ((key, tuple(cls._deserialize_path(path))), value) + for (key, path), value in serialized + ) + + def serialize(self): + path = self.path + return self._serialize_path(path) + + @classmethod + def deserialize(cls, path): + if path is None: + return None + p = cls._deserialize_path(path) return cls.coerce(p) @classmethod diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index df7dd51a8..c50b7d041 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -465,12 +465,16 @@ class Load(Generative, MapperOption): def __getstate__(self): d = self.__dict__.copy() + d["context"] = PathRegistry.serialize_context_dict( + d["context"], ("loader",) + ) d["path"] = self.path.serialize() return d def __setstate__(self, state): self.__dict__.update(state) self.path = PathRegistry.deserialize(self.path) + self.context = PathRegistry.deserialize_context_dict(self.context) def _chop_path(self, to_chop, path): i = -1 |
