MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_refresh_with_lazy

Method test_refresh_with_lazy

test/orm/test_expire.py:2173–2201  ·  view source on GitHub ↗

test that when a lazy loader is set as a trigger on an object's attribute (at the attribute level, not the class level), a refresh() operation doesn't fire the lazy loader or create any problems

(self)

Source from the content-addressed store, hash-verified

2171 assert u.name == "jack"
2172
2173 def test_refresh_with_lazy(self):
2174 """test that when a lazy loader is set as a trigger on an object's
2175 attribute (at the attribute level, not the class level), a refresh()
2176 operation doesn't fire the lazy loader or create any problems"""
2177
2178 User, Address, addresses, users = (
2179 self.classes.User,
2180 self.classes.Address,
2181 self.tables.addresses,
2182 self.tables.users,
2183 )
2184
2185 s = fixture_session()
2186 self.mapper_registry.map_imperatively(
2187 User,
2188 users,
2189 properties={
2190 "addresses": relationship(
2191 self.mapper_registry.map_imperatively(Address, addresses)
2192 )
2193 },
2194 )
2195 q = s.query(User).options(sa.orm.lazyload(User.addresses))
2196 u = q.filter(users.c.id == 8).first()
2197
2198 def go():
2199 s.refresh(u)
2200
2201 self.assert_sql_count(testing.db, go, 1)
2202
2203 def test_refresh_with_eager(self):
2204 """test that a refresh/expire operation loads rows properly and sends

Callers

nothing calls this directly

Calls 9

fixture_sessionFunction · 0.90
relationshipFunction · 0.90
map_imperativelyMethod · 0.80
assert_sql_countMethod · 0.80
optionsMethod · 0.45
queryMethod · 0.45
lazyloadMethod · 0.45
firstMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected