MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _collect_update_commands

Function _collect_update_commands

lib/sqlalchemy/orm/persistence.py:426–637  ·  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

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

Callers 1

_save_objFunction · 0.85

Calls 10

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

Tested by

no test coverage detected