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

Function _postfetch

lib/sqlalchemy/orm/persistence.py:1635–1738  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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

Callers 2

_emit_update_statementsFunction · 0.85
_emit_insert_statementsFunction · 0.85

Calls 7

refresh_flushMethod · 0.80
_expire_attributesMethod · 0.80
getMethod · 0.45
appendMethod · 0.45
popMethod · 0.45
extendMethod · 0.45
populateMethod · 0.45

Tested by

no test coverage detected