Skip to content

fix: use regex to match method definitions in execution orderer - #162

Closed
avarga1 wants to merge 1 commit into
dotflow-io:developfrom
avarga1:fix/bug-134-method-ordering
Closed

fix: use regex to match method definitions in execution orderer#162
avarga1 wants to merge 1 commit into
dotflow-io:developfrom
avarga1:fix/bug-134-method-ordering

Conversation

@avarga1

@avarga1 avarga1 commented Apr 7, 2026

Copy link
Copy Markdown

Summary

Fixes #134

_execution_orderer in execution.py used str.find(f"def {callable_name}") to locate each method in the class source. This matches any line containing that substring, so a method named run would incorrectly match def run_all(...), causing wrong execution order or duplicate entries.

Root cause (execution.py line 78, before fix):

if code.find(f"def {callable_name}") != -1:

Fix: compile a regex that requires the name to be followed by \s*( — i.e., only a true def run(...) declaration matches:

pattern = re.compile(rf"def {re.escape(callable_name)}\s*\(")
if pattern.search(code):

re.escape also guards against method names containing regex metacharacters.

Changes

  • dotflow/core/execution.py: import re; replace str.find with re.compile(...).search
  • tests/mocks/step_class.py: add ActionStepPrefixMethods (methods run and run_all)
  • tests/mocks/__init__.py: export ActionStepPrefixMethods
  • tests/core/test_execution.py: add test_execution_orderer_prefix_methods — verifies each method appears exactly once and run precedes run_all

Test plan

  • All 16 tests/core/test_execution.py tests pass
  • New test test_execution_orderer_prefix_methods explicitly catches the prefix-match regression

🤖 Generated with Claude Code

Replaces str.find(f"def {name}") with a compiled regex
r"def {name}\s*\(" so that a method named e.g. "run" no longer
falsely matches a line containing "def run_all(...)".

Adds ActionStepPrefixMethods mock and test_execution_orderer_prefix_methods
to catch this regression.

Closes dotflow-io#134

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
github-actions Bot changed the base branch from master to develop April 7, 2026 02:55
@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

Base branch was updated from master to develop automatically (this repo integrates changes on develop).

@FernandoCelmer

Copy link
Copy Markdown
Member

Hey @avarga1! Thanks for this — really solid work, especially the test coverage with ActionStepPrefixMethods.

I already pushed a fix for this in PR #163 with a slightly different approach:

  • Uses \b word boundary for stricter matching
  • Uses \s+ instead of a literal space between def and the method name
  • Adds a break after the first match to avoid duplicate entries in the ordered list

Since #163 is already merged, I'm going to close this one. But the test you wrote is great — would you be open to opening a separate PR just with the test (ActionStepPrefixMethods mock + test_execution_orderer_prefix_methods)? It would be a valuable addition to the test suite.

Thanks again for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Method ordering uses string search that can match wrong methods

2 participants