finalize state on states that have been inserted or updated, including calling after_insert/after_update events.
(base_mapper, uowtransaction, states)
| 1511 | |
| 1512 | |
| 1513 | def _finalize_insert_update_commands(base_mapper, uowtransaction, states): |
| 1514 | """finalize state on states that have been inserted or updated, |
| 1515 | including calling after_insert/after_update events. |
| 1516 | |
| 1517 | """ |
| 1518 | for state, state_dict, mapper, connection, has_identity in states: |
| 1519 | if mapper._readonly_props: |
| 1520 | readonly = state.unmodified_intersection( |
| 1521 | [ |
| 1522 | p.key |
| 1523 | for p in mapper._readonly_props |
| 1524 | if ( |
| 1525 | p.expire_on_flush |
| 1526 | and (not p.deferred or p.key in state.dict) |
| 1527 | ) |
| 1528 | or ( |
| 1529 | not p.expire_on_flush |
| 1530 | and not p.deferred |
| 1531 | and p.key not in state.dict |
| 1532 | ) |
| 1533 | ] |
| 1534 | ) |
| 1535 | if readonly: |
| 1536 | state._expire_attributes(state.dict, readonly) |
| 1537 | |
| 1538 | # if eager_defaults option is enabled, load |
| 1539 | # all expired cols. Else if we have a version_id_col, make sure |
| 1540 | # it isn't expired. |
| 1541 | toload_now = [] |
| 1542 | |
| 1543 | # this is specifically to emit a second SELECT for eager_defaults, |
| 1544 | # so only if it's set to True, not "auto" |
| 1545 | if base_mapper.eager_defaults is True: |
| 1546 | toload_now.extend( |
| 1547 | state._unloaded_non_object.intersection( |
| 1548 | mapper._server_default_plus_onupdate_propkeys |
| 1549 | ) |
| 1550 | ) |
| 1551 | |
| 1552 | if ( |
| 1553 | mapper.version_id_col is not None |
| 1554 | and mapper.version_id_generator is False |
| 1555 | ): |
| 1556 | if mapper._version_id_prop.key in state.unloaded: |
| 1557 | toload_now.extend([mapper._version_id_prop.key]) |
| 1558 | |
| 1559 | if toload_now: |
| 1560 | state.key = base_mapper._identity_key_from_state(state) |
| 1561 | stmt = sql.select(mapper) |
| 1562 | loading._load_on_ident( |
| 1563 | uowtransaction.session, |
| 1564 | stmt, |
| 1565 | state.key, |
| 1566 | refresh_state=state, |
| 1567 | only_load_props=toload_now, |
| 1568 | ) |
| 1569 | |
| 1570 | # call after_XXX extensions |
no test coverage detected