Skip to content

Commit a072126

Browse files
thomas-manginclaude
andcommitted
Fix: FlowSpec API flat syntax broken after action dict removal
The route() function in flow/__init__.py was using ParseFlow.action dict to look up actions for commands like 'destination', 'discard', 'interface-set'. Commit f3587b1 removed action dicts from ParseFlowMatch/Then/Scope as part of schema-first refactoring, but ParseFlow.action was built from those dicts, causing KeyError when parsing flat API syntax like: announce flow route destination 133.130.1.219/32 discard interface-set [...] Fix: Use schema-based action lookup via _get_route_action() method instead of the now-empty ParseFlow.action dict. Also removes test E from FLAKY_TESTS since the underlying bug is now fixed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 298c13c commit a072126

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

qa/bin/functional

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ INTERPRETER: str = os.environ.get('INTERPRETER') or os.environ.get('__PYVENV_LAU
5050
# To disable retry feature entirely, comment out the _retry_flaky_tests() call in run_selected()
5151
FLAKY_TESTS: List[str] = [
5252
'D', # api-fast: known to be flaky
53-
'E', # api-flow-merge: server occasionally times out
5453
'W', # api-rr-rib: occasionally fails in batch mode
5554
'7', # api-api: occasionally fails in async mode
5655
]

src/exabgp/configuration/flow/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from exabgp.configuration.core import Parser
1616
from exabgp.configuration.core import Scope
1717
from exabgp.configuration.core import Error
18-
from exabgp.configuration.schema import Container
18+
from exabgp.configuration.schema import Container, Leaf, LeafList
1919

2020
from exabgp.configuration.flow.route import ParseFlowRoute
2121
from exabgp.configuration.flow.route import ParseFlowMatch
@@ -52,9 +52,20 @@ class ParseFlow(Section):
5252
known.update(ParseFlowThen.known)
5353
known.update(ParseFlowScope.known)
5454

55-
action: dict[str | tuple[Any, ...], str] = dict(ParseFlowMatch.action)
56-
action.update(ParseFlowThen.action)
57-
action.update(ParseFlowScope.action)
55+
# Route schema children for action lookup in route() function
56+
_route_schema_children = {
57+
**ParseFlowMatch.schema.children,
58+
**ParseFlowThen.schema.children,
59+
**ParseFlowScope.schema.children,
60+
}
61+
62+
@classmethod
63+
def _get_route_action(cls, command: str) -> str | None:
64+
"""Get action for a flow route command from schema."""
65+
child = cls._route_schema_children.get(command)
66+
if isinstance(child, (Leaf, LeafList)):
67+
return child.action
68+
return None
5869

5970
def __init__(self, parser: Parser, scope: Scope, error: Error) -> None:
6071
Section.__init__(self, parser, scope, error)
@@ -84,7 +95,9 @@ def route(tokeniser: Any) -> list[Change]:
8495
if not command:
8596
break
8697

87-
action: str = ParseFlow.action[command]
98+
action = ParseFlow._get_route_action(command)
99+
if action is None:
100+
raise ValueError(f'flow route: unknown command "{command}"')
88101

89102
if action == 'nlri-add':
90103
handler = cast(Callable[[Any], Any], ParseFlow.known[command])

0 commit comments

Comments
 (0)