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

Function _instance

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

Source from the content-addressed store, hash-verified

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

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