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

ActiveRecord::Persistence#becomes doesn't handle virtual attributes #41195

Closed
SampsonCrowley opened this issue Jan 21, 2021 · 2 comments · Fixed by #42650
Closed

ActiveRecord::Persistence#becomes doesn't handle virtual attributes #41195

SampsonCrowley opened this issue Jan 21, 2021 · 2 comments · Fixed by #42650

Comments

@SampsonCrowley
Copy link
Contributor

Steps to reproduce

Add a virtual attribute to an inherited model, and use #becomes from either the parent to the child or the child to the parent

Expected behavior

Virtual Attributes should be correctly initialized and there shouldn't be any errors, since they have nothing to do with the database

Actual behavior

an ActiveRecord::UnknownAttributeError is thrown if you try to go either direction

System configuration

Rails version: 6.0.3.4 (but I was the one who submitted the last patch for becomes to correctly move items back into the initialize block like they're supposed to be, so I have the current monkey patch for the latest version, it happens on all versions at least from 6+, tested up to 6.1.1)

Ruby version: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux] (but also really not a cause here)

@rails-bot
Copy link

rails-bot bot commented Apr 21, 2021

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 6-1-stable branch or on main, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Apr 21, 2021
@rails-bot rails-bot bot closed this as completed Apr 28, 2021
@intrip
Copy link
Contributor

intrip commented Jul 1, 2021

not stale

@ghiculescu ghiculescu reopened this Jul 1, 2021
@rails-bot rails-bot bot removed the stale label Jul 1, 2021
intrip added a commit to intrip/rails that referenced this issue Aug 24, 2022
When source and target classes have a different set of attributes adapts
attributes such that the extra attributes from target are added.

Fixes rails#41195

Co-authored-by: SampsonCrowley <sampsonsprojects@gmail.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants