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