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

Method _generate_actions

lib/sqlalchemy/orm/unitofwork.py:388–438  ·  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

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