(
context, path, entity, polymorphic_from, option_entities
)
| 1262 | |
| 1263 | |
| 1264 | def _load_subclass_via_in( |
| 1265 | context, path, entity, polymorphic_from, option_entities |
| 1266 | ): |
| 1267 | mapper = entity.mapper |
| 1268 | |
| 1269 | # TODO: polymorphic_from seems to be a Mapper in all cases. |
| 1270 | # this is likely not needed, but as we dont have typing in loading.py |
| 1271 | # yet, err on the safe side |
| 1272 | polymorphic_from_mapper = polymorphic_from.mapper |
| 1273 | not_against_basemost = polymorphic_from_mapper.inherits is not None |
| 1274 | |
| 1275 | zero_idx = len(mapper.base_mapper.primary_key) == 1 |
| 1276 | |
| 1277 | if entity.is_aliased_class or not_against_basemost: |
| 1278 | q, enable_opt, disable_opt = mapper._subclass_load_via_in( |
| 1279 | entity, polymorphic_from |
| 1280 | ) |
| 1281 | else: |
| 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] |
no test coverage detected