Expire attributes in need of newly persisted database state, after an INSERT or UPDATE statement has proceeded for that state.
(
mapper,
uowtransaction,
table,
state,
dict_,
result,
params,
value_params,
isupdate,
returned_defaults,
)
| 1634 | |
| 1635 | |
| 1636 | def _postfetch( |
| 1637 | mapper, |
| 1638 | uowtransaction, |
| 1639 | table, |
| 1640 | state, |
| 1641 | dict_, |
| 1642 | result, |
| 1643 | params, |
| 1644 | value_params, |
| 1645 | isupdate, |
| 1646 | returned_defaults, |
| 1647 | ): |
| 1648 | """Expire attributes in need of newly persisted database state, |
| 1649 | after an INSERT or UPDATE statement has proceeded for that |
| 1650 | state.""" |
| 1651 | |
| 1652 | prefetch_cols = result.context.compiled.prefetch |
| 1653 | postfetch_cols = result.context.compiled.postfetch |
| 1654 | returning_cols = result.context.compiled.effective_returning |
| 1655 | |
| 1656 | if ( |
| 1657 | mapper.version_id_col is not None |
| 1658 | and mapper.version_id_col in mapper._cols_by_table[table] |
| 1659 | ): |
| 1660 | prefetch_cols = list(prefetch_cols) + [mapper.version_id_col] |
| 1661 | |
| 1662 | refresh_flush = bool(mapper.class_manager.dispatch.refresh_flush) |
| 1663 | if refresh_flush: |
| 1664 | load_evt_attrs = [] |
| 1665 | |
| 1666 | if returning_cols: |
| 1667 | row = returned_defaults |
| 1668 | if row is not None: |
| 1669 | for row_value, col in zip(row, returning_cols): |
| 1670 | # pk cols returned from insert are handled |
| 1671 | # distinctly, don't step on the values here |
| 1672 | if col.primary_key and result.context.isinsert: |
| 1673 | continue |
| 1674 | |
| 1675 | # note that columns can be in the "return defaults" that are |
| 1676 | # not mapped to this mapper, typically because they are |
| 1677 | # "excluded", which can be specified directly or also occurs |
| 1678 | # when using declarative w/ single table inheritance |
| 1679 | prop = mapper._columntoproperty.get(col) |
| 1680 | if prop: |
| 1681 | dict_[prop.key] = row_value |
| 1682 | if refresh_flush: |
| 1683 | load_evt_attrs.append(prop.key) |
| 1684 | |
| 1685 | for c in prefetch_cols: |
| 1686 | if c.key in params and c in mapper._columntoproperty: |
| 1687 | pkey = mapper._columntoproperty[c].key |
| 1688 | |
| 1689 | # set prefetched value in dict and also pop from committed_state, |
| 1690 | # since this is new database state that replaces whatever might |
| 1691 | # have previously been fetched (see #10800). this is essentially a |
| 1692 | # shorthand version of set_committed_value(), which could also be |
| 1693 | # used here directly (with more overhead) |
no test coverage detected