MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / do_load

Function do_load

lib/sqlalchemy/orm/loading.py:1284–1331  ·  view source on GitHub ↗
(context, path, states, load_only, effective_entity)

Source from the content-addressed store, hash-verified

1282 q, enable_opt, disable_opt = mapper._subclass_load_via_in_mapper
1283
1284 def do_load(context, path, states, load_only, effective_entity):
1285 if not option_entities:
1286 # filter out states for those that would have selectinloaded
1287 # from another loader
1288 # TODO: we are currently ignoring the case where the
1289 # "selectin_polymorphic" option is used, as this is much more
1290 # complex / specific / very uncommon API use
1291 states = [
1292 (s, v)
1293 for s, v in states
1294 if s.mapper._would_selectin_load_only_from_given_mapper(mapper)
1295 ]
1296
1297 if not states:
1298 return
1299
1300 orig_query = context.query
1301
1302 if path.parent:
1303 enable_opt_lcl = enable_opt._prepend_path(path)
1304 disable_opt_lcl = disable_opt._prepend_path(path)
1305 else:
1306 enable_opt_lcl = enable_opt
1307 disable_opt_lcl = disable_opt
1308 options = (
1309 (enable_opt_lcl,) + orig_query._with_options + (disable_opt_lcl,)
1310 )
1311
1312 q2 = q.options(*options)
1313
1314 q2._compile_options = context.compile_state.default_compile_options
1315 q2._compile_options += {"_current_path": path.parent}
1316
1317 if context.populate_existing:
1318 q2 = q2.execution_options(populate_existing=True)
1319
1320 while states:
1321 chunk = states[0 : _SelectInLoader._chunksize]
1322 states = states[_SelectInLoader._chunksize :]
1323 context.session.execute(
1324 q2,
1325 dict(
1326 primary_keys=[
1327 state.key[1][0] if zero_idx else state.key[1]
1328 for state, load_attrs in chunk
1329 ]
1330 ),
1331 ).unique().scalars().all()
1332
1333 return do_load
1334

Callers

nothing calls this directly

Calls 8

_prepend_pathMethod · 0.45
optionsMethod · 0.45
execution_optionsMethod · 0.45
allMethod · 0.45
scalarsMethod · 0.45
uniqueMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected