Skip to content

[Fix-18074][Task-Plugin] Fix SQL task parameter passing and unsafe regex replacement#18219

Closed
leocook wants to merge 1 commit intoapache:devfrom
leocook:fix-18216-sql-task-param-passing
Closed

[Fix-18074][Task-Plugin] Fix SQL task parameter passing and unsafe regex replacement#18219
leocook wants to merge 1 commit intoapache:devfrom
leocook:fix-18216-sql-task-param-passing

Conversation

@leocook
Copy link
Copy Markdown
Contributor

@leocook leocook commented May 7, 2026

Was this PR generated or assisted by AI?

YES, Opus 4.7

Purpose of the pull request

close #18216

Brief change log

When an upstream SQL task outputs parameter p1 and the downstream task references it via a different parameter name p2 (with value ${p1}), the workflow fails with:

java.lang.IllegalArgumentException: No group with name {p1}
    at java.util.regex.Matcher.appendReplacement(Matcher.java:849)
    at org.apache.dolphinscheduler.plugin.task.sql.SqlTask.replaceOriginalValue(SqlTask.java:496)

Two root causes:

  1. VarPool not injected: CuringParamsServiceImpl.paramParsingPreparation() step 6 only overrides parameters with the same name. Since the downstream task only has p2 and not p1, the upstream VarPool value (p1=111) gets dropped, causing ${p1} to remain unresolved.

  2. Unsafe regex replacement: SqlTask.replaceOriginalValue() uses Matcher.replaceFirst(paramValue) directly, which treats $ as a regex group reference. When the unresolved placeholder ${p1} contains $, it causes the regex engine to crash.

Changes:

  • CuringParamsServiceImpl: Inject VarPool parameters that don't exist in prepareParamsMap for downstream placeholder resolution
  • SqlTask: Use Matcher.quoteReplacement() to safely handle $ in parameter values, and add null safety check

Verify this pull request

This pull request is covered by new unit tests:

  • CuringParamsServiceImplTest.testParamParsingPreparation_varPoolInjectionWhenParamNameNotInLocalParams — verifies upstream VarPool parameter p1 is injected and downstream p2=${p1} is resolved to 111
  • SqlTaskTest.testReplaceOriginalValue_withSpecialCharacters — verifies $, \ characters in values are safely replaced
  • SqlTaskTest.testReplaceOriginalValue_paramNotFound_keepsOriginalText — verifies original text is preserved when parameter is not found
  • SqlTaskTest.testReplaceOriginalValue_paramValueNull_keepsOriginalText — verifies original text is preserved when parameter value is null

Screenshots

Before fix:
image
image

After fix:
image
image

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

…stream and downstream parameter names differ

- Inject VarPool parameters that don't exist in downstream task's local params into prepareParamsMap for placeholder resolution
- Use Matcher.quoteReplacement() in replaceOriginalValue() to prevent $ being treated as regex group reference
- Add null safety check for parameter value before replacement
- Add unit tests for both fixes
@leocook leocook force-pushed the fix-18216-sql-task-param-passing branch from ca92c9e to f8f47a3 Compare May 7, 2026 12:40
@leocook leocook changed the title [Fix-18216][Task-Plugin] Fix SQL task parameter passing fails when upstream and downstream parameter names differ [Fix-18074][Task-Plugin] Fix SQL task parameter passing and unsafe regex replacement May 8, 2026
@leocook
Copy link
Copy Markdown
Contributor Author

leocook commented May 8, 2026

Replaced by new PR with branch fix-18074-sql-parameter-type-passing

@leocook leocook closed this May 8, 2026
@leocook leocook deleted the fix-18216-sql-task-param-passing branch May 8, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [Task Plugin] SQL task parameter passing fails when upstream and downstream parameter names differ

1 participant