MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / test_cache_option

Method test_cache_option

test/orm/test_events.py:116–154  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

114 return maker()
115
116 def test_cache_option(self):
117 User, Address = self.classes("User", "Address")
118
119 with self.sql_execution_asserter(testing.db) as asserter:
120 with self._caching_session_fixture() as session:
121 stmt = (
122 select(User)
123 .where(User.id == 7)
124 .execution_options(cache_key="user7")
125 )
126
127 result = session.execute(stmt)
128
129 eq_(
130 result.scalars().all(),
131 [User(id=7, addresses=[Address(id=1)])],
132 )
133
134 result = session.execute(stmt)
135
136 eq_(
137 result.scalars().all(),
138 [User(id=7, addresses=[Address(id=1)])],
139 )
140
141 asserter.assert_(
142 CompiledSQL(
143 "SELECT users.id, users.name FROM users "
144 "WHERE users.id = :id_1",
145 [{"id_1": 7}],
146 ),
147 CompiledSQL(
148 "SELECT addresses.id, addresses.user_id, "
149 "addresses.email_address "
150 "FROM addresses WHERE :param_1 = addresses.user_id "
151 "ORDER BY addresses.id",
152 [{"param_1": 7}],
153 ),
154 )
155
156 @testing.combinations(
157 ("fixed",), ("payload",), ("dont_cache"), argnames="key_type"

Callers

nothing calls this directly

Calls 13

selectFunction · 0.90
eq_Function · 0.90
CompiledSQLClass · 0.90
UserClass · 0.70
AddressClass · 0.70
execution_optionsMethod · 0.45
whereMethod · 0.45
executeMethod · 0.45
allMethod · 0.45
scalarsMethod · 0.45

Tested by

no test coverage detected