MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _instance

Function _instance

lib/sqlalchemy/orm/loading.py:1075–1233  ·  view source on GitHub ↗
(row)

Source from the content-addressed store, hash-verified

1073 is_not_primary_key = _none_set.intersection
1074
1075 def _instance(row):
1076 # determine the state that we'll be populating
1077 if refresh_identity_key:
1078 # fixed state that we're refreshing
1079 state = refresh_state
1080 instance = state.obj()
1081 dict_ = instance_dict(instance)
1082 isnew = state.runid != runid
1083 currentload = True
1084 loaded_instance = False
1085 else:
1086 # look at the row, see if that identity is in the
1087 # session, or we have to create a new one
1088 identitykey = (
1089 identity_class,
1090 primary_key_getter(row),
1091 identity_token,
1092 )
1093
1094 instance = session_identity_map.get(identitykey)
1095
1096 if instance is not None:
1097 # existing instance
1098 state = instance_state(instance)
1099 dict_ = instance_dict(instance)
1100
1101 isnew = state.runid != runid
1102 currentload = not isnew
1103 loaded_instance = False
1104
1105 if version_check and version_id_getter and not currentload:
1106 _validate_version_id(
1107 mapper, state, dict_, row, version_id_getter
1108 )
1109
1110 else:
1111 # create a new instance
1112
1113 # check for non-NULL values in the primary key columns,
1114 # else no entity is returned for the row
1115 if is_not_primary_key(identitykey[1]):
1116 return None
1117
1118 isnew = True
1119 currentload = True
1120 loaded_instance = True
1121
1122 instance = mapper.class_manager.new_instance()
1123
1124 dict_ = instance_dict(instance)
1125 state = instance_state(instance)
1126 state.key = identitykey
1127 state.identity_token = identity_token
1128
1129 # attach instance to session.
1130 state.session_id = session_id
1131 session_identity_map._add_unpresent(state, identitykey)
1132

Calls 14

instance_dictFunction · 0.85
instance_stateFunction · 0.85
_validate_version_idFunction · 0.85
_populate_fullFunction · 0.85
_warn_for_runid_changedFunction · 0.85
_populate_partialFunction · 0.85
_commitMethod · 0.80
_commit_allMethod · 0.80
add_stateMethod · 0.80
getMethod · 0.45
new_instanceMethod · 0.45
_add_unpresentMethod · 0.45

Tested by

no test coverage detected