-
Notifications
You must be signed in to change notification settings - Fork 76
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
Rails 4.2.0 ActiveType::Object#save fails with ActiveModel::MissingAttributeError can't write unknown attribute `` #31
Comments
We were experienced the same problem, the suggested workaround works. Thanks for the hint |
+1 |
I'm afraid I can't reproduce the issue:
|
@henning-koch Sorry, my explanation was a bit misleading. The call to
|
@henning-koch Here is a minimal Rails app the demonstrates the issue: https://github.com/mattbrictson/active-type-31 To run the demo:
|
+1 |
This is fixed in activerecord 4.2.1. I upgraded my test case from Rails 4.2.0 to 4.2.1 and the bug is no longer present. |
Thanks for the hint. |
Was about to shoot myself dead, thanks for this! 🔫 💩 |
+1 |
Everyone who +1'd this issue: does upgrading to Rails 4.2.1 solve the problem for you? I.e. does it eliminate the need for the |
Upgrading to Rails 4.2.1 solved this problem for me. Thank you for opening this issue and providing a solution. |
Yes, I just upgrade. |
ActiveType |
Update: this affects Rails 4.2.0 only. Rails 4.2.1 does not seem to be affected.
Scenario:
MyForm
inherits fromActiveType::Object
@myform
has validation errors@myform.save
Expectation:
@myform.save
should returnfalse
, since the object is invalidBug:
Instead, I get this exception:
Cause:
save
is called and validation fails, ActiveRecord callsrestore_transaction_record_state
write_attribute(self.class.primary_key, restore_state[:id])
nil
write_attribute
doesn't expect a nil attribute name, so it blows upWorkaround:
I've worked around the bug by explicitly declaring a
MyForm.primary_key
. I'm not sure if this has other consequences, but it seems to work:Here's the relevant stack trace:
The text was updated successfully, but these errors were encountered: