Skip to content

refactor: read touch_update_defaults? from options instead of changeset context#701

Merged
zachdaniel merged 9 commits intoash-project:mainfrom
mbaertschi:refactor/bulk_upsert_updated_at
Mar 2, 2026
Merged

refactor: read touch_update_defaults? from options instead of changeset context#701
zachdaniel merged 9 commits intoash-project:mainfrom
mbaertschi:refactor/bulk_upsert_updated_at

Conversation

@mbaertschi
Copy link
Contributor

@mbaertschi mbaertschi commented Feb 25, 2026

Read the touch_update_defaults? flag from the bulk_create options map
rather than from changeset context.

Depends on ash-project/ash#2590 which adds touch_update_defaults? to the
options passed to data layers. Only merge once that PR is merged and released.

Also support touch_update_defaults? option in non-bulk upsert path

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

…onflict

update_timestamp attributes (e.g. updated_at) were never included in the
ON CONFLICT DO UPDATE SET clause because they have writable?: false and
thus never appear in changeset.attributes. This ensures fields with
update_defaults are always included when an upsert modifies fields.

Closes ash-project#696
…et context

Read the touch_update_defaults? flag from the bulk_create options map
rather than from changeset context.

Depends on ash-project/ash#2590 which adds touch_update_defaults? to the
options passed to data layers. Only merge once that PR is merged and released.
@mbaertschi
Copy link
Contributor Author

@zachdaniel tests will pass once ash-project/ash#2590 is merged into ash

touch_update_defaults? =
Enum.at(changesets, 0).context[:data_layer][:touch_update_defaults?] != false
# Can be disabled via touch_update_defaults?: false option
touch_update_defaults? = Map.get(options, :touch_update_defaults?, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be good to check both here so that its backwards compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@zachdaniel
Copy link
Contributor

Ash has been updated. Mind updating mix.exs to depend on the latest version as part of this PR?

@zachdaniel
Copy link
Contributor

Same for the ash_sqlite version 🙇

@zachdaniel zachdaniel merged commit 3ed809e into ash-project:main Mar 2, 2026
67 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

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.

2 participants