MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / new_version

Method new_version

examples/versioned_rows/versioned_map.py:121–150  ·  view source on GitHub ↗
(self, session)

Source from the content-addressed store, hash-verified

119 return element
120
121 def new_version(self, session):
122 # convert to an INSERT
123 make_transient(self)
124 self.id = None
125
126 # history of the 'elements' collection.
127 # this is a tuple of groups: (added, unchanged, deleted)
128 hist = attributes.get_history(self, "elements")
129
130 # rewrite the 'elements' collection
131 # from scratch, removing all history
132 attributes.set_committed_value(self, "elements", {})
133
134 # new elements in the "added" group
135 # are moved to our new collection.
136 for elem in hist.added:
137 self.elements[elem.name] = elem
138
139 # copy elements in the 'unchanged' group.
140 # the new ones associate with the new ConfigData,
141 # the old ones stay associated with the old ConfigData
142 for elem in hist.unchanged:
143 self.elements[elem.name] = ConfigValueAssociation(
144 elem.config_value
145 )
146
147 # we also need to expire changes on each ConfigValueAssociation
148 # that is to remain associated with the old ConfigData.
149 # Here, each one takes care of that in its new_version()
150 # method, though we could do that here as well.
151
152
153class ConfigValueAssociation(Base):

Callers 1

before_flushFunction · 0.45

Calls 4

make_transientFunction · 0.90
get_historyMethod · 0.45
set_committed_valueMethod · 0.45

Tested by

no test coverage detected