MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _generate_actions

Method _generate_actions

lib/sqlalchemy/orm/unitofwork.py:390–440  ·  view source on GitHub ↗

Generate the full, unsorted collection of PostSortRecs as well as dependency pairs for this UOWTransaction.

(self)

Source from the content-addressed store, hash-verified

388 yield state
389
390 def _generate_actions(self):
391 """Generate the full, unsorted collection of PostSortRecs as
392 well as dependency pairs for this UOWTransaction.
393
394 """
395 # execute presort_actions, until all states
396 # have been processed. a presort_action might
397 # add new states to the uow.
398 while True:
399 ret = False
400 for action in list(self.presort_actions.values()):
401 if action.execute(self):
402 ret = True
403 if not ret:
404 break
405
406 # see if the graph of mapper dependencies has cycles.
407 self.cycles = cycles = topological.find_cycles(
408 self.dependencies, list(self.postsort_actions.values())
409 )
410
411 if cycles:
412 # if yes, break the per-mapper actions into
413 # per-state actions
414 convert = {
415 rec: set(rec.per_state_flush_actions(self)) for rec in cycles
416 }
417
418 # rewrite the existing dependencies to point to
419 # the per-state actions for those per-mapper actions
420 # that were broken up.
421 for edge in list(self.dependencies):
422 if (
423 None in edge
424 or edge[0].disabled
425 or edge[1].disabled
426 or cycles.issuperset(edge)
427 ):
428 self.dependencies.remove(edge)
429 elif edge[0] in cycles:
430 self.dependencies.remove(edge)
431 for dep in convert[edge[0]]:
432 self.dependencies.add((dep, edge[1]))
433 elif edge[1] in cycles:
434 self.dependencies.remove(edge)
435 for dep in convert[edge[1]]:
436 self.dependencies.add((edge[0], dep))
437
438 return {
439 a for a in self.postsort_actions.values() if not a.disabled
440 }.difference(cycles)
441
442 def execute(self) -> None:
443 postsort_actions = self._generate_actions()

Callers 2

executeMethod · 0.95
_assert_uow_sizeMethod · 0.80

Calls 7

valuesMethod · 0.45
executeMethod · 0.45
issupersetMethod · 0.45
removeMethod · 0.45
addMethod · 0.45
differenceMethod · 0.45

Tested by 1

_assert_uow_sizeMethod · 0.64