[Sqlalchemy-tickets] Issue #4159: legacy setstate for loader options not tested (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2018-01-10 20:24:09
|
New issue 4159: legacy setstate for loader options not tested https://bitbucket.org/zzzeek/sqlalchemy/issues/4159/legacy-setstate-for-loader-options-not Michael Bayer: ``` #!diff diff --git a/test/orm/test_options.py b/test/orm/test_options.py index 731aee1e5..9d3b8b702 100644 --- a/test/orm/test_options.py +++ b/test/orm/test_options.py @@ -890,6 +890,86 @@ class OptionsNoPropTest(_fixtures.FixtureTest): joinedload(eager_option)) +class PickleTest(PathTest, QueryTest): + + def _option_fixture(self, *arg): + return strategy_options._UnboundLoad._from_keys( + strategy_options._UnboundLoad.joinedload, arg, True, {}) + + def test_modern_opt_getstate(self): + User = self.classes.User + + sess = Session() + q = sess.query(User) + + opt = self._option_fixture(User.addresses) + eq_( + opt.__getstate__(), + { + '_is_chain_link': False, + 'local_opts': {}, + 'is_class_strategy': False, + 'path': [(User, 'addresses', None)], + 'propagate_to_loaders': True, + '_to_bind': [opt], + 'strategy': (('lazy', 'joined'),)} + ) + + def test_modern_opt_setstate(self): + User = self.classes.User + + opt = strategy_options._UnboundLoad.__new__( + strategy_options._UnboundLoad) + state = { + '_is_chain_link': False, + 'local_opts': {}, + 'is_class_strategy': False, + 'path': [(User, 'addresses', None)], + 'propagate_to_loaders': True, + '_to_bind': [opt], + 'strategy': (('lazy', 'joined'),)} + + opt.__setstate__(state) + + query = create_session().query(User) + attr = {} + load = opt._bind_loader( + [ent.entity_zero for ent in query._mapper_entities], + query._current_path, attr, False) + + eq_( + load.path, + inspect(User)._path_registry + [User.addresses.property][inspect(self.classes.Address)]) + + def test_legacy_opt_setstate(self): + User = self.classes.User + + opt = strategy_options._UnboundLoad.__new__( + strategy_options._UnboundLoad) + state = { + '_is_chain_link': False, + 'local_opts': {}, + 'is_class_strategy': False, + 'path': [(User, 'addresses')], + 'propagate_to_loaders': True, + '_to_bind': [opt], + 'strategy': (('lazy', 'joined'),)} + + opt.__setstate__(state) + + query = create_session().query(User) + attr = {} + load = opt._bind_loader( + [ent.entity_zero for ent in query._mapper_entities], + query._current_path, attr, False) + + eq_( + load.path, + inspect(User)._path_registry + [User.addresses.property][inspect(self.classes.Address)]) + + class LocalOptsTest(PathTest, QueryTest): @classmethod def setup_class(cls): ``` |