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

Rails 5.0.1 support #13302

Merged
merged 5 commits into from
Jan 10, 2017
Merged

Rails 5.0.1 support #13302

merged 5 commits into from
Jan 10, 2017

Conversation

chrisarcand
Copy link
Member

@chrisarcand chrisarcand commented Dec 22, 2016

The new patch release of Rails sadly introduced a large regression (even as a patch release) due to our use of Active Record internals for virtual attributes. These changes allow ManageIQ to run on the latest.

See individual commits for details.

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

Have a feeling this is just the beginning here.
Thanks for the fix

@@ -405,6 +405,9 @@ def load_schema!

def define_virtual_attribute(name, cast_type, uses: nil, arel: nil)
attribute_types[name] = cast_type
if ActiveRecord::VERSION::MAJOR >= 5
_default_attributes[name] = ActiveRecord::Attribute.uninitialized(name, cast_type)
Copy link
Member

Choose a reason for hiding this comment

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

darn, but looks like it works

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems fine to me.. underscore notwithstanding, I think writing to _default_attributes is at a pretty similar level of internalness as attribute_types. (It bypasses the define_default_attribute private helper, but fundamentally, setting up those two hashes is what define_attribute does, and this method is intended to parallel that.)

No need for the version conditional, though -- unless it's fundamentally changed since I left it, this whole file is only expected to work on 5.0+.

@kbrock
Copy link
Member

kbrock commented Dec 23, 2016

ugh. looks like there are still a few errors here. This is going to be tricky

@chessbyte chessbyte added the wip label Jan 3, 2017
@miq-bot
Copy link
Member

miq-bot commented Jan 4, 2017

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@chrisarcand chrisarcand force-pushed the rails-5-0-1-support branch 2 times, most recently from fcf5dbd to 506b6e7 Compare January 5, 2017 19:15
@chrisarcand chrisarcand force-pushed the rails-5-0-1-support branch 2 times, most recently from 317e111 to 74bf0af Compare January 9, 2017 15:51
@miq-bot
Copy link
Member

miq-bot commented Jan 9, 2017

This pull request is not mergeable. Please rebase and repush.

skateman and others added 5 commits January 9, 2017 13:14
There's no reason ActionCable should be specified independently
of Rails as railties locks them at exact versions. That is, actioncable
is included and loaded in the stack regardless of being set here, and setting
action cable like this actually forces the entire framework at 5.0.1
anyway.
This overwrites the default method for this by adding an additional
check to the proc that is defined with the AttributeSet::Builder to
check to see if the key should be provided a default from the
`_default_attributes` hash to not only check to see if it is a column
from the database, but also a virtual_attribute.

The functionality added by:

rails/rails@3e37a8b#diff-6c8fd220c92c2b25aa29891b59d00c04

was meant to help vanilla Rails' "virtual attributes" by assigning a
default value on model instantiation.  This is not what used to be done
for any attributes (database or otherwise) besides the primary key for
that model.  What this does is includes `virtual_attributes` as
attributes that aren't defined with a default value, along the database
column attributes.
In the following:

rails/rails#25146

Rails added a regression to making nested joins with references to those
joins in the WHERE clause, and this causes an error when running this
test suite in Rails 5.0.1.

This has been addressed in Rails with:

rails/rails#27598

And has been merged into master, but it is likely that Rails 5.0.1 will
not be pulled from Rubygems, and the ManageIQ will fail to run tests
properly with that version of Rails.

Because of that, and to allow the tests to function in the same way, the
simplest thing to do is to stringify the keys manually avoid the error
for now.  This is against the convention (most Rails devs prefer
symbols), but this allows the tests to remain as they were.
@chrisarcand chrisarcand changed the title [WIP] Rails 5.0.1 support Rails 5.0.1 support Jan 9, 2017
@chrisarcand chrisarcand removed the wip label Jan 9, 2017
@chrisarcand
Copy link
Member Author

@Fryguy or @jrafanie Wanna give this a look over? Should be ready to roll (initial OK by @kbrock is outdated)

@miq-bot
Copy link
Member

miq-bot commented Jan 9, 2017

Checked commits chrisarcand/manageiq@4a7b1ee~...4e96ee4 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
3 files checked, 2 offenses detected

spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

Ok. Now I really approve this PR.

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

LGTM

# Display errors in both development.log and STDOUT
Rails.logger.warn(errstr)
warn(errstr)
end
Copy link
Member

Choose a reason for hiding this comment

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

🎉 🔥 🕺

@@ -386,6 +386,14 @@ def virtual_attribute_names
end
end

def attributes_builder
@attributes_builder ||= ::ActiveRecord::AttributeSet::Builder.new(attribute_types, primary_key) do |name|
unless columns_hash.key?(name) || virtual_attribute?(name)
Copy link
Member

Choose a reason for hiding this comment

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

I would normally whine about unless with an || but since the original rails code has unless... I'm good with keeping it as close to the original code. I'll just say my brain still needs to convert this to an if.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 to original code thought and even still I think it looks good 😄 If there were a negation in there it would be a whole different story.

@Fryguy Fryguy merged commit fa1c0df into ManageIQ:master Jan 10, 2017
@Fryguy Fryguy added this to the Sprint 52 Ending Jan 16, 2017 milestone Jan 10, 2017
@simaishi simaishi mentioned this pull request Mar 17, 2017
@jrafanie jrafanie deleted the rails-5-0-1-support branch March 17, 2017 15:41
simaishi pushed a commit that referenced this pull request Mar 17, 2017
Rails 5.0.1 support
(cherry picked from commit fa1c0df)
@simaishi
Copy link
Contributor

Euwe backport details:

$ git log -1
commit f977c39d744e028b6041e8eb112791fdf9ccfa39
Author: Jason Frey <[email protected]>
Date:   Tue Jan 10 10:39:04 2017 -0500

    Merge pull request #13302 from chrisarcand/rails-5-0-1-support
    
    Rails 5.0.1 support
    (cherry picked from commit fa1c0df702354e008816a62c9034add823505d3d)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants