MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _collect_update_commands

Function _collect_update_commands

lib/sqlalchemy/orm/persistence.py:428–634  ·  view source on GitHub ↗

Identify sets of values to use in UPDATE statements for a list of states. This function works intricately with the history system to determine exactly what values should be updated as well as how the row should be matched within an UPDATE statement. Includes some tricky scenari

(
    uowtransaction,
    table,
    states_to_update,
    *,
    bulk=False,
    use_orm_update_stmt=None,
    include_bulk_keys=(),
)

Source from the content-addressed store, hash-verified

426
427
428def _collect_update_commands(
429 uowtransaction,
430 table,
431 states_to_update,
432 *,
433 bulk=False,
434 use_orm_update_stmt=None,
435 include_bulk_keys=(),
436):
437 """Identify sets of values to use in UPDATE statements for a
438 list of states.
439
440 This function works intricately with the history system
441 to determine exactly what values should be updated
442 as well as how the row should be matched within an UPDATE
443 statement. Includes some tricky scenarios where the primary
444 key of an object might have been changed.
445
446 """
447
448 for (
449 state,
450 state_dict,
451 mapper,
452 connection,
453 update_version_id,
454 ) in states_to_update:
455 if table not in mapper._pks_by_table:
456 continue
457
458 pks = mapper._pks_by_table[table]
459
460 if use_orm_update_stmt is not None:
461 # TODO: ordered values, etc
462 value_params = use_orm_update_stmt._values
463 else:
464 value_params = {}
465
466 propkey_to_col = mapper._propkey_to_col[table]
467
468 if bulk:
469 # keys here are mapped attribute keys, so
470 # look at mapper attribute keys for pk
471 params = {
472 propkey_to_col[propkey].key: state_dict[propkey]
473 for propkey in set(propkey_to_col)
474 .intersection(state_dict)
475 .difference(mapper._pk_attr_keys_by_table[table])
476 }
477 has_all_defaults = True
478 else:
479 params = {}
480 for propkey in set(propkey_to_col).intersection(
481 state.committed_state
482 ):
483 value = state_dict[propkey]
484 col = propkey_to_col[propkey]
485

Callers 1

save_objFunction · 0.85

Calls 11

differenceMethod · 0.45
intersectionMethod · 0.45
__clause_element__Method · 0.45
issubsetMethod · 0.45
valuesMethod · 0.45
get_historyMethod · 0.45
getMethod · 0.45
joinMethod · 0.45
popMethod · 0.45
updateMethod · 0.45
populateMethod · 0.45

Tested by

no test coverage detected