Skip to content

fix: group the alternation in enum regex validators - #7878

Open
goranai wants to merge 1 commit into
1Panel-dev:v2from
goranai:fix/regex-validator-alternation
Open

goranai wants to merge 1 commit into
1Panel-dev:v2from
goranai:fix/regex-validator-alternation

Conversation

@goranai

@goranai goranai commented Nov 12, 2026

Copy link
Copy Markdown

What this PR does / why we need it?

Patterns like ^embedding|keywords|blend$ mean ^embedding OR keywords OR blend$. So values such as xkeywords pass the validator and later fail with a 500. This wraps the alternatives in a group in 16 patterns across 10 files, for example ^(embedding|keywords|blend)$.

Closes #7877

Summary of your change

  • 16 one-line pattern edits in 10 files. No other code touched. The allowed value lists are not changed.
  • Behavior change: values that only contain, start with or end with an allowed value (for example xkeywords, registerx, xuser) are now rejected with the validator message. Exact values behave as before. DRF CharField trims whitespace before validators run, so blend still passes as blend.
  • Newly rejected junk values for the tool node type (i_tool_node.py): before, things like integer, point or array[string] passed validation, because they contain int or array. Then valid_reference_value logged "Unsupported this type" and passed the value through. Now they fail validation. The UI only sends string, int, dict, array, float, boolean, so UI users are not affected. A workflow saved through the raw API or an old import with such a type would now fail validation. I could not check database data for this.
  • The tool node set string|int|dict|array|float|boolean is kept exactly as it is at HEAD. It matches the UI options and valid_reference_value.
  • Left alone on purpose: ToolInputField in apps/tools/serializers/tool.py has the same two patterns, but nothing references the class. If you want it changed, its type list does not include boolean, and that is your decision.
  • Not fixed here: valid_type allows knowledge, but model_message_dict only has the key dataset, so valid/knowledge/50 still returns a 500 before and after this PR. This is a separate bug.
  • Checked with 57,668 cases per side on DRF CharField plus RegexValidator using the real patterns from the source. The old patterns accepted 12,445 wrong values. The new ones accept 0, and no valid value is rejected. A 3,000 example Hypothesis property also passed. I also ran python -m py_compile on the 10 changed files, typos on them, and ruff check gives the same findings as before.
  • No unit test added because the repo has no test setup for these serializers that runs without Postgres. This repo's CI workflows only build images and run a typos check.

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed. (not ticked: no test added, CI has no test job)
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed. (no docs impact, left for the maintainer)

Validated with Claude Opus 5.5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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] Regex validators like "^embedding|keywords|blend$" accept values that only contain a keyword

1 participant