Identify sets of values to use in UPDATE statements for a list of states within a post_update operation.
(
base_mapper, uowtransaction, table, states_to_update, post_update_cols
)
| 638 | |
| 639 | |
| 640 | def _collect_post_update_commands( |
| 641 | base_mapper, uowtransaction, table, states_to_update, post_update_cols |
| 642 | ): |
| 643 | """Identify sets of values to use in UPDATE statements for a |
| 644 | list of states within a post_update operation. |
| 645 | |
| 646 | """ |
| 647 | |
| 648 | for ( |
| 649 | state, |
| 650 | state_dict, |
| 651 | mapper, |
| 652 | connection, |
| 653 | update_version_id, |
| 654 | ) in states_to_update: |
| 655 | # assert table in mapper._pks_by_table |
| 656 | |
| 657 | pks = mapper._pks_by_table[table] |
| 658 | params = {} |
| 659 | hasdata = False |
| 660 | |
| 661 | for col in mapper._cols_by_table[table]: |
| 662 | if col in pks: |
| 663 | params[col._label] = mapper._get_state_attr_by_column( |
| 664 | state, state_dict, col, passive=attributes.PASSIVE_OFF |
| 665 | ) |
| 666 | |
| 667 | elif col in post_update_cols or col.onupdate is not None: |
| 668 | prop = mapper._columntoproperty[col] |
| 669 | history = state.manager[prop.key].impl.get_history( |
| 670 | state, state_dict, attributes.PASSIVE_NO_INITIALIZE |
| 671 | ) |
| 672 | if history.added: |
| 673 | value = history.added[0] |
| 674 | params[col.key] = value |
| 675 | hasdata = True |
| 676 | if hasdata: |
| 677 | if ( |
| 678 | update_version_id is not None |
| 679 | and mapper.version_id_col in mapper._cols_by_table[table] |
| 680 | ): |
| 681 | col = mapper.version_id_col |
| 682 | params[col._label] = update_version_id |
| 683 | |
| 684 | if ( |
| 685 | bool(state.key) |
| 686 | and col.key not in params |
| 687 | and mapper.version_id_generator is not False |
| 688 | ): |
| 689 | val = mapper.version_id_generator(update_version_id) |
| 690 | params[col.key] = val |
| 691 | yield state, state_dict, mapper, connection, params |
| 692 | |
| 693 | |
| 694 | def _collect_delete_commands( |
no test coverage detected