-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
field/3
's :writable
seems to ignore the :insert
option
#4524
Comments
Hi @lucavenir , Thank you for the report. I believe the update is silently not happening. We just filter the non-updatable fields out before performing the operation. Are you able to select from the database afterwards to see what the real value is? In the test I just did, this is the case. Then I guess the question is should do something more than silently ignore. |
Hello @gentoid, Silently ignoring is coherent with much of But in the commented test above, I check for the updated struct, and I find it to be updated even though it should silently ignore it. I tried that as well and the test fails. So you're not able to reproduce this? If that's the case I'll try and reproduce this in a sandbox. |
You might have to pull the data again with If you are not using the |
Hello @greg-rychlewski, Indeed performing another Now what's left (in my mind) is how to determine if this is expected behavior, or rather, a desired behavior. Let me preface that I'm a 110% newbie on About
If so, why wouldn't the database return |
When you have a changeset, we only send the fields you changed to the database. If any of the fields in the database have been changed meanwhile, that will actually not be reflected on the struct, unless you set There may still be arguments for changing the behaviour here though. Unsure. :) |
Yeah I guess I didn't read the documentation well enough. Thanks for the quick response! 💕 I understand what the current behavior is, so, it's expected behavior. I fail to understand what value does this behavior bring. But I accept it now. What my simple grug mind would think (or desire?) is this process:
Instead, what grug receives now is: "here's the fields that effectively changed PLUS whatever you passed me in that might not have changed". Am I understanding this right? I'm not sure what I can make of this (again, consider that I'm a 110% newb). I'd leave the debate to people way smarter than me, I just wanted to share my 2 cents as a person in a learning process. In any case, knowing that |
In your particular case, I'd say the simplest solution would be to not cast |
Namely, defining a different changeset for updates, right? The (great, btw!!) community on discord gave me this first answer, but I wanted to explore and learn all the possibilities. In your opinion, what's the most idiomatic way of solving my particular case? Having two changesets or exploiting this |
For now, the changeset approach is the way to go but we plan to fix what you reported so it just works. :) |
@lucavenir Thank you for the report and discussion. This never even crossed my mind. |
Thank you guys! You're breathtaking! The fact that you've discussed and addressed this in less than 24h is awesome, beyond any possible imagination. Have a great day! 👍 |
Elixir version
1.16.2
Database and Version
PostgreSQL 16.1
Ecto Versions
3.12.4
Database Adapter and Versions (postgrex, myxql, etc)
postgrex 0.19.1
Current behavior
I wanted to apply this
:writable
option mentioned in field/3' documentation. Unluckilywritable: insert
seems to be ignored.Given this schema:
This tests fails:
Expected behavior
I'd expect the previous test to have the commented parts to pass, and the uncommented parts to fail, i.e. I'd expect this test to pass:
(meaning: I'm not sure if the
:insert
option ignores the write or returns an error, but surely it shouldn't allow an edit!)The text was updated successfully, but these errors were encountered: