(context, path, states, load_only, effective_entity)
| 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 |
nothing calls this directly
no test coverage detected