Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@stevebrambilla
Copy link
Contributor

The way atomic validations currently work is that it picks the first primary key field and uses that for the validation expression, assigning the current value to itself if the condition passes.

In our case, the selected primary key field is also the distribution column used for Citus, so we get this error:

** (Postgrex.Error) ERROR 0A000 (feature_not_supported) modifying the partition value of rows is not allowed

This PR makes two changes around this:

  1. If there is already another atomic attribute in the changeset, prefer using it.
  2. Added a new atomic_validation_default_target_attribute to :resource so resources can specify a compatible attribute.

The atomic validation attribute now take the first of:

  • First atomic attribute already in the changeset
  • The resource's atomic_validation_default_target_attribute
  • The resource's first primary key field (current behaviour)

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

|> Ash.create!()

# Validation passes for recent books, fails for older ones.
assert {:ok, %Book{year: 2020}} = Book.validation_without_update(recent_book)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to validate that this does not prevent the underlying change to this attribute. Shouldn't this be 2021?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two actions on Book, one of them does the atomic_update to increment to 2021 and the other (this one) doesn't.

As soon as you have another atomic attribute in the changeset, it gets chosen as the validation attribute, so the only way to exercise the default target attribute is not having any existing atomic attributes there.

Want me to add a separate test just validating that we can still update :title?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be great yes, but probably other tests would have failed in retrospect. Can't hurt IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, just pushed another commit with the extra test

@zachdaniel zachdaniel merged commit 306db0d into ash-project:main Oct 8, 2025
43 checks passed
@zachdaniel
Copy link
Contributor

πŸš€ Thank you for your contribution! πŸš€

@capoccias capoccias mentioned this pull request Oct 15, 2025
2 tasks
@zachdaniel
Copy link
Contributor

@stevebrambilla just a note for you in case it matters, this logic has been slightly modified to actually choose the last changing attribute in the atomics list, not the first.

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