Skip to content

test: cover bulk upsert dropping records when select excludes identity keys - #809

Open
marcnnn wants to merge 1 commit into
ash-project:mainfrom
marcnnn:regression-test-bulk-upsert-drops-records
Open

test: cover bulk upsert dropping records when select excludes identity keys#809
marcnnn wants to merge 1 commit into
ash-project:mainfrom
marcnnn:regression-test-bulk-upsert-drops-records

Conversation

@marcnnn

@marcnnn marcnnn commented Jul 29, 2026

Copy link
Copy Markdown

On upsert the columns that need to be selected to match the updated rows with the rows from the database are not selected anymore so upsert result is empty even if the data is written into the db.

This is a regression that is related to #786 and #638

In my case, an upsert_identity with unique_index defines the upsert semantic already, so the select was left out and is filled by the upsert reactor with the empty list. But the unique index is constructed with two fields not only one like the test, i can add this as well?

My dependabot branch for the ash_postgres update from 2.10.0 to 2.11.0 failed CI
The tests reproduce a simplified version of the problem.

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

…y keys

A bulk upsert pairs each returned row back up with its changeset by the upsert
identity's keys, but the `RETURNING` list is built from the action's
`action_select` alone. When the select doesn't include those keys, every row
reads back with `nil` for each one, nothing correlates, and every record is
dropped from the result - while the rows are still written. The caller sees
`%Ash.BulkResult{status: :success, errors: [], records: []}` for a batch that
inserted or updated fine.

These two tests currently FAIL on main. They are untagged, so they cover both
the `INSERT ... ON CONFLICT` path and the PostgreSQL 17+ `MERGE` path.

`:upsert_with_no_filter` is used because it declares no changes and no
notifiers, which makes its `action_select` just the primary key - an explicit
`select` therefore can't widen it to include the identity key.
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.

1 participant