Repository navigation
Handle empty on_conflict_fields in ConflictResolution.get_conflict_clause for UPDATE - #41638
Conversation
There was a problem hiding this comment.
📋 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 requiresDO UPDATEto specify a conflict target (e.g.,ON CONFLICT (col1, col2) DO UPDATE ...). Instead of generating invalid SQL (ON CONFLICT DO UPDATE ...),ConflictResolutionshould validate and reject emptyon_conflict_fieldswhenaction == "UPDATE". - There is a trailing whitespace line added at the end of
sdks/python/apache_beam/ml/rag/ingestion/postgres_common.pythat will fail formatting/lint checks.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @claudevdm for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
7d186fa to
4264612
Compare
fixes #41632
ConflictResolution.get_conflict_clause()inpostgres_common.pyemitted invalid SQL (ON CONFLICT () DO UPDATE SET ...) whenon_conflict_fields=[]andaction="UPDATE". UnlikeDO NOTHING, PostgreSQL requires a conflict target forON CONFLICT ... DO UPDATE.ValueErrorinConflictResolution.get_conflict_clause()whenaction="UPDATE"andon_conflict_fieldsis empty.ON CONFLICT DO NOTHING(without extra spaces) whenaction="IGNORE"andon_conflict_fieldsis empty.postgres_common_test.pycovering emptyon_conflict_fieldsforUPDATE(ValueError) andIGNORE, as well as non-emptystrandlist[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.