-
Notifications
You must be signed in to change notification settings - Fork 900
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,18 +46,29 @@ def seed_record(path, report) | |
|
||
_log.info("#{report.new_record? ? "Creating" : "Updating"} MiqReport #{filename.inspect}") | ||
|
||
yml = YAML.load_file(path).symbolize_keys | ||
yml = YAML.load_file(path).symbolize_keys | ||
name = yml[:menu_name].strip | ||
|
||
attrs = yml.slice(*column_names_symbols) | ||
attrs.delete(:id) | ||
attrs[:filename] = filename | ||
attrs[:file_mtime] = mtime | ||
attrs[:name] = yml[:menu_name].strip | ||
attrs[:name] = name | ||
attrs[:priority] = File.basename(path).split("_").first.to_i | ||
attrs[:rpt_group] = File.basename(File.dirname(path)).split("_").last | ||
attrs[:rpt_type] = "Default" | ||
attrs[:template_type] = path.start_with?(REPORT_DIR.to_s) ? "report" : "compare" | ||
|
||
report.update_attributes!(attrs) | ||
begin | ||
report.update_attributes!(attrs) | ||
rescue ActiveRecord::RecordInvalid | ||
duplicate = find_by(:name => name) | ||
if duplicate&.rpt_type == "Custom" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😩 Nooooo... I hate this syntax... (pedantic/personal preference) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) ) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, The (Again: My personal preference, and it goes against There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
_log.warn("A custom report already exists with the name #{duplicate.name.inspect}. Skipping...") | ||
else | ||
raise | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
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.