(
self,
our_states,
none_states,
query_info,
q,
context,
execution_options,
chunksize,
)
| 3406 | ) |
| 3407 | |
| 3408 | def _load_via_child( |
| 3409 | self, |
| 3410 | our_states, |
| 3411 | none_states, |
| 3412 | query_info, |
| 3413 | q, |
| 3414 | context, |
| 3415 | execution_options, |
| 3416 | chunksize, |
| 3417 | ): |
| 3418 | uselist = self.uselist |
| 3419 | n_pk = query_info.n_pk |
| 3420 | |
| 3421 | # this sort is really for the benefit of the unit tests |
| 3422 | our_keys = sorted(our_states) |
| 3423 | while our_keys: |
| 3424 | chunk = our_keys[0:chunksize] |
| 3425 | our_keys = our_keys[chunksize:] |
| 3426 | primary_keys = [ |
| 3427 | key[0] if query_info.zero_idx else key for key in chunk |
| 3428 | ] |
| 3429 | result = context.session.execute( |
| 3430 | q, |
| 3431 | params={"primary_keys": primary_keys}, |
| 3432 | execution_options=execution_options, |
| 3433 | ) |
| 3434 | if result.context is not None and result.context.requires_uniquing: |
| 3435 | rows = result.unique() |
| 3436 | else: |
| 3437 | rows = result._raw_all_tuples() |
| 3438 | data = {row[:n_pk]: row[n_pk] for row in rows} |
| 3439 | |
| 3440 | for key in chunk: |
| 3441 | # for a real foreign key and no concurrent changes to the |
| 3442 | # DB while running this method, "key" is always present in |
| 3443 | # data. However, for primaryjoins without real foreign keys |
| 3444 | # a non-None primaryjoin condition may still refer to no |
| 3445 | # related object. |
| 3446 | related_obj = data.get(key, None) |
| 3447 | for state, dict_, overwrite in our_states[key]: |
| 3448 | if not overwrite and self.key in dict_: |
| 3449 | continue |
| 3450 | |
| 3451 | state.get_impl(self.key).set_committed_value( |
| 3452 | state, |
| 3453 | dict_, |
| 3454 | related_obj if not uselist else [related_obj], |
| 3455 | ) |
| 3456 | # populate none states with empty value / collection |
| 3457 | for state, dict_, overwrite in none_states: |
| 3458 | if not overwrite and self.key in dict_: |
| 3459 | continue |
| 3460 | |
| 3461 | # note it's OK if this is a uselist=True attribute, the empty |
| 3462 | # collection will be populated |
| 3463 | state.get_impl(self.key).set_committed_value(state, dict_, None) |
| 3464 | |
| 3465 | def _load_via_parent( |
no test coverage detected