MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _postfetch_post_update

Function _postfetch_post_update

lib/sqlalchemy/orm/persistence.py:1586–1633  ·  view source on GitHub ↗
(
    mapper, uowtransaction, table, state, dict_, result, params
)

Source from the content-addressed store, hash-verified

1584
1585
1586def _postfetch_post_update(
1587 mapper, uowtransaction, table, state, dict_, result, params
1588):
1589 needs_version_id = (
1590 mapper.version_id_col is not None
1591 and mapper.version_id_col in mapper._cols_by_table[table]
1592 )
1593
1594 if not uowtransaction.is_deleted(state):
1595 # post updating after a regular INSERT or UPDATE, do a full postfetch
1596 prefetch_cols = result.context.compiled.prefetch
1597 postfetch_cols = result.context.compiled.postfetch
1598 elif needs_version_id:
1599 # post updating before a DELETE with a version_id_col, need to
1600 # postfetch just version_id_col
1601 prefetch_cols = postfetch_cols = ()
1602 else:
1603 # post updating before a DELETE without a version_id_col,
1604 # don't need to postfetch
1605 return
1606
1607 if needs_version_id:
1608 prefetch_cols = list(prefetch_cols) + [mapper.version_id_col]
1609
1610 refresh_flush = bool(mapper.class_manager.dispatch.refresh_flush)
1611 if refresh_flush:
1612 load_evt_attrs = []
1613
1614 for c in prefetch_cols:
1615 if c.key in params and c in mapper._columntoproperty:
1616 dict_[mapper._columntoproperty[c].key] = params[c.key]
1617 if refresh_flush:
1618 load_evt_attrs.append(mapper._columntoproperty[c].key)
1619
1620 if refresh_flush and load_evt_attrs:
1621 mapper.class_manager.dispatch.refresh_flush(
1622 state, uowtransaction, load_evt_attrs
1623 )
1624
1625 if postfetch_cols:
1626 state._expire_attributes(
1627 state.dict,
1628 [
1629 mapper._columntoproperty[c].key
1630 for c in postfetch_cols
1631 if c in mapper._columntoproperty
1632 ],
1633 )
1634
1635
1636def _postfetch(

Callers 1

Calls 4

is_deletedMethod · 0.80
refresh_flushMethod · 0.80
_expire_attributesMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected