From 43d4863142934de1b02dc64a001e463943f768ed Mon Sep 17 00:00:00 2001 From: Anthony Volk Date: Wed, 27 Nov 2024 22:53:14 +0100 Subject: [PATCH] fix: Fix tests --- policyengine_api/routes/economy_routes.py | 4 +++- policyengine_api/services/policy_service.py | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/policyengine_api/routes/economy_routes.py b/policyengine_api/routes/economy_routes.py index 450aea00..da5cb876 100644 --- a/policyengine_api/routes/economy_routes.py +++ b/policyengine_api/routes/economy_routes.py @@ -12,7 +12,9 @@ @validate_country @economy_bp.route("//over/", methods=["GET"]) -def get_economic_impact(country_id: str, policy_id: str | int, baseline_policy_id: str | int): +def get_economic_impact( + country_id: str, policy_id: str | int, baseline_policy_id: str | int +): policy_id = int(policy_id or get_current_law_policy_id(country_id)) baseline_policy_id = int( diff --git a/policyengine_api/services/policy_service.py b/policyengine_api/services/policy_service.py index 80cf98b6..c332ab9c 100644 --- a/policyengine_api/services/policy_service.py +++ b/policyengine_api/services/policy_service.py @@ -28,16 +28,18 @@ def get_policy(self, country_id: str, policy_id: int) -> dict | None: try: # If no policy found, this will return None - row: LegacyRow = database.query( + row: LegacyRow | None = database.query( "SELECT * FROM policy WHERE country_id = ? AND id = ?", (country_id, policy_id), ).fetchone() # policy_json is JSON and must be loaded, if present; to enable, # we must convert the row to a dictionary - policy = dict(row) - if policy and policy["policy_json"]: - policy["policy_json"] = json.loads(policy["policy_json"]) + policy = None + if row: + policy = dict(row) + if policy["policy_json"]: + policy["policy_json"] = json.loads(policy["policy_json"]) return policy except Exception as e: print(f"Error getting policy: {str(e)}")