From 275a76a1a031f87b0d22f6ffef8a21810dd8be13 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 9 Mar 2026 14:20:27 +0530 Subject: [PATCH] fix: preserve 404s for invalid rollup filters --- .../timeseries/average_report_builder.rb | 2 +- .../reports/timeseries/count_report_builder.rb | 2 +- .../timeseries/average_report_builder_spec.rb | 15 +++++++++++++++ .../timeseries/count_report_builder_spec.rb | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/builders/v2/reports/timeseries/average_report_builder.rb b/app/builders/v2/reports/timeseries/average_report_builder.rb index 87bedb5b7..4103807fe 100644 --- a/app/builders/v2/reports/timeseries/average_report_builder.rb +++ b/app/builders/v2/reports/timeseries/average_report_builder.rb @@ -63,7 +63,7 @@ class V2::Reports::Timeseries::AverageReportBuilder < V2::Reports::Timeseries::B end def dimension_id_for_rollup - params[:type].to_s == 'account' ? account.id : params[:id].to_i + params[:type].to_s == 'account' ? account.id : scope.id end def group_and_aggregate_rollup(rollup_rows) diff --git a/app/builders/v2/reports/timeseries/count_report_builder.rb b/app/builders/v2/reports/timeseries/count_report_builder.rb index bd44aaa49..0192c242c 100644 --- a/app/builders/v2/reports/timeseries/count_report_builder.rb +++ b/app/builders/v2/reports/timeseries/count_report_builder.rb @@ -60,7 +60,7 @@ class V2::Reports::Timeseries::CountReportBuilder < V2::Reports::Timeseries::Bas end def dimension_id_for_rollup - params[:type].to_s == 'account' ? account.id : params[:id].to_i + params[:type].to_s == 'account' ? account.id : scope.id end def group_and_aggregate_rollup_counts(rollup_rows) diff --git a/spec/builders/v2/reports/timeseries/average_report_builder_spec.rb b/spec/builders/v2/reports/timeseries/average_report_builder_spec.rb index 3b67307b3..347fc9944 100644 --- a/spec/builders/v2/reports/timeseries/average_report_builder_spec.rb +++ b/spec/builders/v2/reports/timeseries/average_report_builder_spec.rb @@ -262,5 +262,20 @@ describe V2::Reports::Timeseries::AverageReportBuilder do expect(subject.aggregate_value).to eq 91.0 end end + + context 'when rollups are enabled and the agent does not exist' do + let(:filter_type) { :agent } + let(:filter_id) { '999999' } + let(:timezone_offset) { '0' } + + before do + account.update!(reporting_timezone: 'Etc/UTC') + allow(account).to receive(:feature_enabled?).with('reporting_events_rollup').and_return(true) + end + + it 'raises record not found to preserve raw path behavior' do + expect { subject.aggregate_value }.to raise_error(ActiveRecord::RecordNotFound) + end + end end end diff --git a/spec/builders/v2/reports/timeseries/count_report_builder_spec.rb b/spec/builders/v2/reports/timeseries/count_report_builder_spec.rb index 77199958f..b45f32123 100644 --- a/spec/builders/v2/reports/timeseries/count_report_builder_spec.rb +++ b/spec/builders/v2/reports/timeseries/count_report_builder_spec.rb @@ -86,6 +86,23 @@ describe V2::Reports::Timeseries::CountReportBuilder do expect(subject.aggregate_value).to eq(2) end + context 'when rollups are enabled and the agent does not exist' do + let(:timezone_offset) { '0' } + + let(:params) do + super().merge(id: '999999') + end + + before do + account.update!(reporting_timezone: 'Etc/UTC') + allow(account).to receive(:feature_enabled?).with('reporting_events_rollup').and_return(true) + end + + it 'raises record not found to preserve raw path behavior' do + expect { subject.aggregate_value }.to raise_error(ActiveRecord::RecordNotFound) + end + end + context 'when querying account2' do subject { described_class.new(account2, params) }