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

Add save hooks on MiqReportResult to remove groupings #17598

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/models/miq_report_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ class MiqReportResult < ApplicationRecord
end
end

# These two hooks prevent temporary chargeback aggregation data to be
# retained in each miq_report_results row, which was found and fixed as part
# of the following BZ:
#
# https://bugzilla.redhat.com/show_bug.cgi?id=1590908
#
# These two hooks remove extra data on the `@extras` instance variable, since
# it is not necessary to be saved to the DB, but allows it to be retained for
# the remainder of the object's instantiation. The `after_commit` hook
# specifically is probably overkill, but allows us to not break existing code
# that expects the temporary chargeback data in the instantiated object.
before_save { @_extra_groupings = report.extras.delete(:grouping) if report.kind_of?(MiqReport) }
after_commit { report.extras[:grouping] = @_extra_groupings if report.kind_of?(MiqReport) }

delegate :table, :to => :report_results, :allow_nil => true

def result_set
Expand Down
17 changes: 17 additions & 0 deletions spec/models/miq_report_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@
expect(report_result.report_results.table.data).not_to be_nil
end

it "should not include `extras[:grouping]` in the report column" do
MiqReport.seed_report(name = "Vendor and Guest OS")
rpt = MiqReport.where(:name => name).last
rpt.generate_table(:userid => "test")
report_result = rpt.build_create_results(:userid => "test")

report_result.report
report_result.report.extras[:grouping] = { "extra data" => "not saved" }
report_result.save

result_reload = MiqReportResult.last

expect(report_result.report.kind_of?(MiqReport)).to be_truthy
expect(result_reload.report.extras[:grouping]).to be_nil
expect(report_result.report.extras[:grouping]).to eq("extra data" => "not saved")
end

context "for miq_report_result is used different miq_group_id than user's current id" do
before do
MiqUserRole.seed
Expand Down