Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly handle changing_attributes check with from in create #1584

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

vonagam
Copy link
Contributor

@vonagam vonagam commented Nov 5, 2024

This piece of code in changing_attributes check does not make sense to me right now:

if Keyword.has_key?(opts, :from) && changeset.action_type == :create do
  if opts[:from] == nil do
    {:halt, false}
  else
    {:cont, expr}
  end
else

It says that from: nil is bad but from: :whatever is good.

First, I assume that the branches were supposed to be reversed - if from: nil then it matches create otherwise not.

Second, but that supposed reversal is also bad as it does not take into account attribute's default value (so it is questionable that the change is from nil) and also ignores potential presence of to option.

So instead just do return false for create changeset if from option is present.

@zachdaniel zachdaniel merged commit 0ea315a into ash-project:main Nov 5, 2024
32 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

@vonagam vonagam deleted the fix-changing-attributes-check branch November 5, 2024 18:24
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