Skip to content

Commit ac78108

Browse files
committed
Fix backchaining
Search anchor point only in Selector, Sequence nodes to avoid Decorators with children When latching multiple chains always latch next chain to first one to avoid problems that may arise when last chain were simplified to one action and don't have a sequence anymore
1 parent 3373b3b commit ac78108

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/redis_release/bht/backchain.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
def find_chain_anchor_point(
1818
root: Behaviour,
1919
) -> Sequence:
20+
"""Find the anchor point (Sequence) to which we can latch the next chain.
21+
22+
We assume that the anchor point is the leftmost non empty Sequence in the tree.
23+
"""
2024
for child in root.children:
21-
if len(child.children) > 1:
25+
if (isinstance(child, Sequence) or isinstance(child, Selector)) and len(
26+
child.children
27+
) > 0:
2228
return find_chain_anchor_point(child)
2329
if isinstance(root, Sequence):
2430
return root
@@ -31,7 +37,6 @@ def latch_chains(*chains: Union[Selector, Sequence]) -> None:
3137
first = chains[0]
3238
for chain in chains[1:]:
3339
latch_chain_to_chain(first, chain)
34-
first = chain
3540

3641

3742
def latch_chain_to_chain(
@@ -55,7 +60,7 @@ def latch_chain_to_chain(
5560
next_postcondition: Optional[Behaviour] = None
5661
anchor_precondition: Optional[Behaviour] = None
5762

58-
logger.debug(f"Latching {next.name} to {anchor_point.name}")
63+
logger.debug(f'Latching "{next.name}" to "{anchor_point.name}"')
5964

6065
# Trying to guess from the structure which node may be a postcondition
6166
# Later we compare it with the anchor point precondition and when they match

0 commit comments

Comments
 (0)