Skip to content

Handle empty on_conflict_fields in ConflictResolution.get_conflict_clause for UPDATE - #41638

Open
arijeetmukherjee3108-droid wants to merge 1 commit into
apache:masterfrom
arijeetmukherjee3108-droid:fix-postgres-conflict-clause
Open

arijeetmukherjee3108-droid wants to merge 1 commit into
apache:masterfrom
arijeetmukherjee3108-droid:fix-postgres-conflict-clause

Conversation

@arijeetmukherjee3108-droid

@arijeetmukherjee3108-droid arijeetmukherjee3108-droid commented Nov 24, 2026 •

Copy link
Copy Markdown

fixes #41632

ConflictResolution.get_conflict_clause() in postgres_common.py emitted invalid SQL (ON CONFLICT () DO UPDATE SET ...) when on_conflict_fields=[] and action="UPDATE". Unlike DO NOTHING, PostgreSQL requires a conflict target for ON CONFLICT ... DO UPDATE.

  • Raise ValueError in ConflictResolution.get_conflict_clause() when action="UPDATE" and on_conflict_fields is empty.
  • Preserve ON CONFLICT DO NOTHING (without extra spaces) when action="IGNORE" and on_conflict_fields is empty.
  • Add unit tests in postgres_common_test.py covering empty on_conflict_fields for UPDATE (ValueError) and IGNORE, as well as non-empty str and list[str] conflict targets.

Tested locally with pytest sdks/python/apache_beam/ml/rag/ingestion/postgres_common_test.py sdks/python/apache_beam/ml/rag/ingestion/base_test.py -v.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR modifies ConflictResolution.get_conflict_clause() in postgres_common.py to omit empty parentheses when on_conflict_fields is empty and action="UPDATE" (producing ON CONFLICT DO UPDATE SET ...), and fixes a double-space formatting issue when action="IGNORE" has empty conflict fields. However, PostgreSQL syntax strictly requires a conflict target for ON CONFLICT ... DO UPDATE, meaning ON CONFLICT DO UPDATE is invalid PostgreSQL and will fail at runtime.

🔍 General Feedback

  • Unlike DO NOTHING, PostgreSQL requires DO UPDATE to specify a conflict target (e.g., ON CONFLICT (col1, col2) DO UPDATE ...). Instead of generating invalid SQL (ON CONFLICT DO UPDATE ...), ConflictResolution should validate and reject empty on_conflict_fields when action == "UPDATE".
  • There is a trailing whitespace line added at the end of sdks/python/apache_beam/ml/rag/ingestion/postgres_common.py that will fail formatting/lint checks.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions github-actions Bot added python size/s S: 10-49 lines changed labels Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @claudevdm for label python.
Backup reviewer: jrmccluskey (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ConflictResolution.get_conflict_clause() produces invalid SQL when on_conflict_fields is empty for UPDATE

1 participant