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