fix: preserve 404s for invalid rollup filters

This commit is contained in:
Shivam Mishra
2026-03-09 14:20:27 +05:30
parent 6f127d86b9
commit 275a76a1a0
4 changed files with 34 additions and 2 deletions
@@ -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)
@@ -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)
@@ -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
@@ -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) }