fix: Improve duplicate flow name handling and add comprehensive tests (#8962)
* ✨ (flows.py): Improve flow naming logic to handle duplicate names more effectively and accurately 📝 (test_rename_flow_to_save.py): Add unit tests to ensure correct numbering and handling of duplicate flow names * [autofix.ci] apply automated fixes * ✨ (test_rename_flow_to_save.py): refactor test functions to remove unnecessary session parameter and improve code readability * 📝 (flows.py): improve regex pattern to extract numbers only from flows following a specific naming convention to avoid extracting numbers from the original flow name if it contains parentheses * [autofix.ci] apply automated fixes * 📝 (flows.py): improve comments for better readability and understanding of regex usage in extracting numbers from flow names --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
bd8e3a162a
commit
c1d417adf2
2 changed files with 172 additions and 1 deletions
|
|
@ -83,7 +83,15 @@ async def _new_flow(
|
|||
)
|
||||
).all()
|
||||
if flows:
|
||||
extract_number = re.compile(r"\((\d+)\)$")
|
||||
# Use regex to extract numbers only from flows that follow the copy naming pattern:
|
||||
# "{original_name} ({number})"
|
||||
# This avoids extracting numbers from the original flow name if it naturally contains parentheses
|
||||
#
|
||||
# Examples:
|
||||
# - For flow "My Flow": matches "My Flow (1)", "My Flow (2)" → extracts 1, 2
|
||||
# - For flow "Analytics (Q1)": matches "Analytics (Q1) (1)" → extracts 1
|
||||
# but does NOT match "Analytics (Q1)" → avoids extracting the original "1"
|
||||
extract_number = re.compile(rf"^{re.escape(flow.name)} \((\d+)\)$")
|
||||
numbers = []
|
||||
for _flow in flows:
|
||||
result = extract_number.search(_flow.name)
|
||||
|
|
@ -91,6 +99,8 @@ async def _new_flow(
|
|||
numbers.append(int(result.groups(1)[0]))
|
||||
if numbers:
|
||||
flow.name = f"{flow.name} ({max(numbers) + 1})"
|
||||
else:
|
||||
flow.name = f"{flow.name} (1)"
|
||||
else:
|
||||
flow.name = f"{flow.name} (1)"
|
||||
# Now check if the endpoint is unique
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue