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

MiqReport.seed skips a report when a custom report exists with same name #18377

Merged
merged 1 commit into from
Jan 22, 2019

Conversation

Fryguy
Copy link
Member

@Fryguy Fryguy commented Jan 21, 2019

Prefer the custom report over the seeded report and log a warning when
this case occurs.

@NickLaMuro @jrafanie Please review.

This should fix the issue with some of the UI team having custom reports with the exact same name as the seeded reports and it blowing up.

@Fryguy Fryguy added the bug label Jan 21, 2019
@Fryguy Fryguy requested a review from jrafanie January 21, 2019 16:16
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.

Looks good to me. The comments are minor and/or personal gripes. Not worth holding up the PR.

app/models/miq_report/seeding.rb Outdated Show resolved Hide resolved
report.update_attributes!(attrs)
rescue ActiveRecord::RecordInvalid
duplicate = find_by(:name => name)
if duplicate&.rpt_type == "Custom"
Copy link
Member

Choose a reason for hiding this comment

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

😩 Nooooo... I hate this syntax...

(pedantic/personal preference)

Copy link
Member Author

Choose a reason for hiding this comment

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

Out of curiosity what is the syntax you'd prefer (FWIW I like this syntax :) )

Copy link
Member

@NickLaMuro NickLaMuro Jan 21, 2019

Choose a reason for hiding this comment

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

@Fryguy while it is "Rails specific", and I usually would reach for something out of STDLIB, .try would be preferred, or just explicitly doing it via a not duplicate.nil? and duplicate.rpt_type == "Custom".

The & symbol is already overloaded in my opinion, and is used for AND (&&), and bit-wise AND (&) already, so I just think this is a obscure syntax that doesn't help with readability in any form. Would have preferred a more verbose method like attempt() even over a single character operator. </rant> </2cents>

(Again: My personal preference, and it goes against rubocop's rule set, so not worth the change).

Copy link
Member

Choose a reason for hiding this comment

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

You would think with a name like lonely operator, it would attract more friends.

I don't like how it looks like invalid syntax or how it tries to make ugliness less ugly but besides that, I can dig it.

report.update_attributes!(attrs)
rescue ActiveRecord::RecordInvalid
duplicate = find_by(:name => name)
Copy link
Member

Choose a reason for hiding this comment

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

Thankfully this should be only happening on a rare occasion, so shouldn't be a big deal as far as adding to the N+1 count. 👍

That said, if we wanted, we could maybe raise these all at the end, and do a single find query. Probably not worth it, just a thought.

spec/models/miq_report/seeding_spec.rb Outdated Show resolved Hide resolved
@ZitaNemeckova
Copy link
Contributor

Run bin/update with corrupted DB and it worked. 👍

@Fryguy
Copy link
Member Author

Fryguy commented Jan 21, 2019

@NickLaMuro I'll fix some of the minor comments

Prefer the custom report over the seeded report and log a warning when
this case occurs.
@Fryguy Fryguy force-pushed the fix_report_seed_dups branch from 75031d3 to f05016c Compare January 22, 2019 14:37
@Fryguy
Copy link
Member Author

Fryguy commented Jan 22, 2019

@NickLaMuro Updated.

@miq-bot
Copy link
Member

miq-bot commented Jan 22, 2019

Checked commit Fryguy@f05016c with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🍪

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.

Besides bad puns, I have no other useful comments. It looks good.

@jrafanie jrafanie merged commit 9a48f1d into ManageIQ:master Jan 22, 2019
@jrafanie jrafanie added this to the Sprint 104 Ending Feb 4, 2019 milestone Jan 22, 2019
@Fryguy Fryguy deleted the fix_report_seed_dups branch January 23, 2019 17:43
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.

5 participants