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

[WIP] update MiqReport::Search to include all columns #18176

Closed
wants to merge 1 commit into from

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Nov 8, 2018

Ok, backdrop: report.yml file.

Columns for the screen? Use col_order.
Associated models? Use includes_for_find.

The foreign_key needed to bring back those associated models?
That is tricky, I guess you could declare all the col_order again in the cols attribute.

rails 5.0

We were bringing back data for all models in a single query (sometimes to our detriment).
We did not need the extra associated models' foreign_key ids because we had all the associated models' data to create the associated AR records.

rails 5.1, Before PR:

We were bring back associated models in additional queries, but the foreign_key necessary to bring them back was not present. This caused and exception / 500 error.

rails 5.1, after PR:

We are now bringing back more columns, specifically the foreign_key.
The associated models able to be queried.

Concerns

It appears the rules as to what models are brought back by the primary query changed again. It used to require includes(:model2), then it required 'includes(:model2).references(:model2)` in rails 4.x.
Now there appears to be another rule.

There was a bug in 5.0 where has_many associations would be part of the primary query. Which brought back many many rows. So this could be the driver of the 5.1 change. But that is speculation

But what ever the reason, these associated foreign_key ids should be brought back, for all versions of rails.

@kbrock kbrock force-pushed the rails-5-1-column-select branch 2 times, most recently from 0f86947 to cf4c0e1 Compare November 8, 2018 22:28
@jrafanie
Copy link
Member

jrafanie commented Nov 8, 2018

@kbrock I think I follow the change you make here but it's still unclear what exactly changed in rails 5.1 to break us. How did the foreign_key get included in the select in 5.0 and not 5.1?

@kbrock kbrock changed the title update MiqReport::Search to include all columns [WIP] update MiqReport::Search to include all columns Nov 12, 2018
@miq-bot miq-bot added the wip label Nov 12, 2018
@kbrock kbrock force-pushed the rails-5-1-column-select branch from cf4c0e1 to 799ef64 Compare November 14, 2018 17:15
@kbrock
Copy link
Member Author

kbrock commented Nov 14, 2018

WIP status - I'm looking through rails searching for the actual issue

This code is working and I like this change.
After I track down the rails change, plan on submitting this PR to be merged

When generating a query for a report, ensure that the columns necessary
to join to other models are brought back.

If a report needs additional columns for join models and the models are
not part of the includes_for_find attribute, then ensure all columns
including the join keys are in cols: attribute, and just the visible
columns are in the col_order attribute
@kbrock kbrock force-pushed the rails-5-1-column-select branch from 799ef64 to f9cacf8 Compare November 14, 2018 20:23
@miq-bot
Copy link
Member

miq-bot commented Nov 14, 2018

Checked commit kbrock@f9cacf8 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🍰

@jrafanie
Copy link
Member

@kbrock where do we stand on this PR? I'm still using this commit on my rails 5.1 branch and I'm not sure if it's going away or will be replaced.

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

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

First off, sorry for the delayed review on this. Saw it come back in my inbox with LJ's comment and realized I never gave a proper review.

I think what you have here works for the bug that has been observed, but without knowing the true cause, I don't think it is wise to merge it until we have a better idea of what we are dealing with.

@@ -92,7 +92,19 @@ def paged_view_search(options = {})

search_options = options.merge(:class => db, :conditions => conditions, :include_for_find => includes)
search_options.merge!(:limit => limit, :offset => offset, :order => order) if order
search_options[:extra_cols] = va_sql_cols if va_sql_cols.present?

extra_cols = if includes
Copy link
Member

Choose a reason for hiding this comment

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

Kinda seems like this should be put in it's own method. va_sql_cols is just a memoized method as well, so you could toss it there, but I could see the argument that this should be it's own method and probably makes sense that it is.

Copy link
Member

Choose a reason for hiding this comment

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

I am also confused why this is needed, which leads back to LJ's comment here:

#18176 (comment)

The :extra_cols attribute on Rbac (**cough** **cough** nick is the original author **cough** **cough**) was meant to add additional columns and not remove ones that were already there (even if the default Arel.star was originally just assumed). So something seems borked in Rails if we need to start adding the foreign keys ourselves, or we broke something in manageiq along the way.

Is there possibly an additional .select in this report that is causing the issue? I also have some changes in #18353 that are affecting the results for :extra_cols that might be beneficial or detrimental to what you have here as well.

extra_cols = if includes
includes.keys.map do |rel|
if (rel = db_class.reflect_on_association(rel))
# adding primary_key is probably overkill.
Copy link
Member

Choose a reason for hiding this comment

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

You should always have the primary key just in case an association is needed on the model down the line, or you are immediately converting the results to a lower level data model. I think in the case of reports, we aren't doing that, so the use of relations might be necessary.

I would say remove this comment, just so there is no confusion.

@kbrock
Copy link
Member Author

kbrock commented Jan 16, 2019

@jrafanie yes, I am trying to figure out the issue here

@miq-bot
Copy link
Member

miq-bot commented Mar 22, 2019

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

@kbrock
Copy link
Member Author

kbrock commented Jun 15, 2019

not going this route. modifying the way includes is supported under the covers.

Core rails also fails when you select(:name).includes(:model).references(:model)

@kbrock kbrock closed this Jun 15, 2019
@kbrock kbrock deleted the rails-5-1-column-select branch June 15, 2019 20:17
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.

4 participants