Skip to content

Commit 8ac6a79

Browse files
authored
Merge pull request #3726 from PolicyEngine/feat/deprecate-national-with-breakdowns
Deprecate national-with-breakdowns dataset selectors
2 parents 864b0e5 + 1735f68 commit 8ac6a79

8 files changed

Lines changed: 74 additions & 29 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecated the `national-with-breakdowns`, `national-with-breakdowns-test`, and
2+
`national-with-datasets` economy dataset aliases. API v1 now treats these as
3+
the default certified dataset and ignores the old district-breakdown query flag,
4+
so congressional district output can pass through from the sim API.

policyengine_api/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def get_bundle_default_dataset_option(country_id: str) -> dict:
173173
) or _resolve_distribution_version(_dist_versions, "policyengine-core", "policyengine")
174174

175175
RUNTIME_CACHE_SCHEMA_VERSIONS = {
176-
"economy_impact": 1,
176+
"economy_impact": 2,
177177
"report_output": 1,
178178
}
179179

policyengine_api/openapi_spec.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,14 @@ paths:
773773
required: false
774774
schema:
775775
type: string
776+
- name: include_district_breakdowns
777+
in: query
778+
description: Deprecated no-op. Congressional district results are returned automatically for US national and state-level simulations.
779+
deprecated: true
780+
required: false
781+
schema:
782+
type: boolean
783+
default: false
776784
responses:
777785
200:
778786
description: Calculating economic impact.
@@ -888,7 +896,8 @@ paths:
888896
type: string
889897
- name: include_district_breakdowns
890898
in: query
891-
description: Whether to include congressional district breakdowns for US national simulations.
899+
description: Deprecated no-op. Congressional district results are returned automatically for US national and state-level simulations.
900+
deprecated: true
892901
required: false
893902
schema:
894903
type: boolean

policyengine_api/routes/economy_routes.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,8 @@ def get_economic_impact(country_id: str, policy_id: int, baseline_policy_id: int
5353
dataset = options.pop("dataset", "default")
5454
time_period = options.pop("time_period")
5555

56-
# Handle district breakdowns - only for US national simulations
57-
include_district_breakdowns_raw = options.pop(
58-
"include_district_breakdowns", "false"
59-
)
60-
include_district_breakdowns = include_district_breakdowns_raw.lower() == "true"
61-
if include_district_breakdowns and country_id == "us" and region == "us":
62-
dataset = "national-with-breakdowns"
56+
# Deprecated no-op retained for older app-v2 callers.
57+
options.pop("include_district_breakdowns", None)
6358
target: Literal["general", "cliff"] = options.pop("target", "general")
6459
api_version = options.pop("version", COUNTRY_PACKAGE_VERSIONS.get(country_id))
6560

@@ -125,12 +120,8 @@ def get_budget_window_economic_impact(
125120
except (TypeError, ValueError):
126121
return _bad_request_response("window_size must be an integer")
127122

128-
include_district_breakdowns_raw = options.pop(
129-
"include_district_breakdowns", "false"
130-
)
131-
include_district_breakdowns = include_district_breakdowns_raw.lower() == "true"
132-
if include_district_breakdowns and country_id == "us" and region == "us":
133-
dataset = "national-with-breakdowns"
123+
# Deprecated no-op retained for older app-v2 callers.
124+
options.pop("include_district_breakdowns", None)
134125

135126
target: Literal["general", "cliff"] = options.pop("target", "general")
136127
if target != "general":

policyengine_api/services/economy_service.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,10 +1168,12 @@ def _validate_us_region(self, region: str) -> None:
11681168
else:
11691169
raise ValueError(f"Invalid US region: '{region}'")
11701170

1171-
# Dataset keywords that are passed directly to the simulation API.
1172-
PASSTHROUGH_DATASETS = {
1171+
# Deprecated dataset aliases accepted for older app-v2 callers. These no
1172+
# longer route to special sim API datasets.
1173+
DEPRECATED_BREAKDOWN_DATASETS = {
11731174
"national-with-breakdowns",
11741175
"national-with-breakdowns-test",
1176+
"national-with-datasets",
11751177
}
11761178
DEPRECATED_DATASETS_BY_COUNTRY = {
11771179
"us": {"cps", "enhanced_cps"},
@@ -1183,6 +1185,8 @@ def _canonical_dataset(
11831185
) -> str:
11841186
if not dataset:
11851187
return "default"
1188+
if dataset in self.DEPRECATED_BREAKDOWN_DATASETS:
1189+
return "default"
11861190
if dataset == get_bundle_default_dataset(country_id):
11871191
return "default"
11881192
return dataset
@@ -1200,6 +1204,8 @@ def _setup_data(
12001204
"""
12011205
if dataset in (None, "", "default"):
12021206
return None
1207+
if dataset in self.DEPRECATED_BREAKDOWN_DATASETS:
1208+
return None
12031209

12041210
deprecated_datasets = self.DEPRECATED_DATASETS_BY_COUNTRY.get(country_id, set())
12051211
if dataset in deprecated_datasets:
@@ -1211,9 +1217,6 @@ def _setup_data(
12111217
if dataset == get_bundle_default_dataset(country_id):
12121218
return None
12131219

1214-
if dataset in self.PASSTHROUGH_DATASETS:
1215-
return dataset
1216-
12171220
if "://" in dataset:
12181221
return dataset
12191222

tests/to_refactor/python/test_economy_budget_window_routes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_budget_window_route_passes_version_to_service(
178178
@patch(
179179
"policyengine_api.routes.economy_routes.economy_service.get_budget_window_economic_impact"
180180
)
181-
def test_budget_window_route_uses_breakdown_dataset_for_us_national_request(
181+
def test_budget_window_route_ignores_deprecated_breakdown_flag(
182182
mock_get_budget_window_economic_impact, rest_client
183183
):
184184
mock_get_budget_window_economic_impact.return_value = _mock_budget_window_result()
@@ -192,8 +192,7 @@ def test_budget_window_route_uses_breakdown_dataset_for_us_national_request(
192192
assert response.status_code == 200
193193
mock_get_budget_window_economic_impact.assert_called_once()
194194
assert (
195-
mock_get_budget_window_economic_impact.call_args.kwargs["dataset"]
196-
== "national-with-breakdowns"
195+
mock_get_budget_window_economic_impact.call_args.kwargs["dataset"] == "default"
197196
)
198197

199198

tests/unit/routes/test_economy_dataset_validation.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import json
2-
from unittest.mock import patch
2+
from unittest.mock import Mock, patch
33

44
from flask import Flask
55

66
from policyengine_api.routes.economy_routes import economy_bp
77

88

9+
def _mock_economic_result():
10+
mock_result = Mock()
11+
mock_result.to_dict.return_value = {
12+
"status": "ok",
13+
"data": {"congressional_district_impact": {"districts": []}},
14+
}
15+
return mock_result
16+
17+
918
def _client_with_economy_blueprint():
1019
app = Flask(__name__)
1120
app.config["TESTING"] = True
@@ -32,6 +41,25 @@ def test_economy_route_returns_bad_request_for_dataset_validation_error(
3241
assert "enhanced_cps" in payload["message"]
3342

3443

44+
@patch("policyengine_api.routes.economy_routes.economy_service.get_economic_impact")
45+
def test_economy_route_ignores_deprecated_breakdown_flag(mock_get_economic_impact):
46+
mock_get_economic_impact.return_value = _mock_economic_result()
47+
client = _client_with_economy_blueprint()
48+
49+
response = client.get(
50+
"/us/economy/123/over/456"
51+
"?region=us&time_period=2026&include_district_breakdowns=true"
52+
)
53+
payload = json.loads(response.data)
54+
55+
assert response.status_code == 200
56+
assert payload["status"] == "ok"
57+
assert payload["result"]["congressional_district_impact"] == {"districts": []}
58+
mock_get_economic_impact.assert_called_once()
59+
assert mock_get_economic_impact.call_args.kwargs["dataset"] == "default"
60+
assert mock_get_economic_impact.call_args.kwargs["options"] == {}
61+
62+
3563
@patch(
3664
"policyengine_api.routes.economy_routes.economy_service.get_budget_window_economic_impact"
3765
)

tests/unit/services/test_economy_service.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,20 +1980,24 @@ def test__given_invalid_country_default__omits_data(self, mock_logger):
19801980
result = service._setup_data("invalid", "region")
19811981
assert result is None
19821982

1983-
def test__given_passthrough_dataset__returns_dataset_directly(self):
1983+
def test__given_deprecated_breakdown_dataset__omits_data(self):
19841984
service = EconomyService()
19851985
result = service._setup_data("us", "us", dataset="national-with-breakdowns")
1986-
assert result == "national-with-breakdowns"
1986+
assert result is None
19871987

1988-
def test__given_passthrough_test_dataset__returns_dataset_directly(
1988+
def test__given_deprecated_breakdown_test_dataset__omits_data(
19891989
self,
19901990
):
1991-
# Test with passthrough test dataset
19921991
service = EconomyService()
19931992
result = service._setup_data(
19941993
"us", "us", dataset="national-with-breakdowns-test"
19951994
)
1996-
assert result == "national-with-breakdowns-test"
1995+
assert result is None
1996+
1997+
def test__given_deprecated_national_with_datasets__omits_data(self):
1998+
service = EconomyService()
1999+
result = service._setup_data("us", "us", dataset="national-with-datasets")
2000+
assert result is None
19972001

19982002
def test__given_explicit_us_enhanced_cps__raises_value_error(self):
19992003
service = EconomyService()
@@ -2044,10 +2048,17 @@ def test__given_bundle_default_dataset_name__canonicalizes_setup_identity(self):
20442048
**common_args,
20452049
dataset="populace_us_2024",
20462050
)
2051+
deprecated_breakdown_setup = service._build_economic_impact_setup_options(
2052+
**common_args,
2053+
dataset="national-with-breakdowns",
2054+
)
20472055

20482056
assert bundle_default_setup.dataset == "default"
20492057
assert bundle_default_setup.data_version is None
20502058
assert bundle_default_setup.options_hash == default_setup.options_hash
2059+
assert deprecated_breakdown_setup.dataset == "default"
2060+
assert deprecated_breakdown_setup.data_version is None
2061+
assert deprecated_breakdown_setup.options_hash == default_setup.options_hash
20512062

20522063
def test__given_unknown_dataset__passes_through_legacy_designator(self):
20532064
service = EconomyService()

0 commit comments

Comments
 (0)