From 7a707c55182bccf7d9359b371faae8237c66ffba Mon Sep 17 00:00:00 2001 From: v-lerie Date: Mon, 23 Jun 2025 00:35:29 -0400 Subject: [PATCH 1/2] Fixed user profile page error --- policyengine_api/gcp_logging.py | 12 ++++++++++-- policyengine_api/routes/user_profile_routes.py | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/policyengine_api/gcp_logging.py b/policyengine_api/gcp_logging.py index 1696af5d0..345dd446b 100644 --- a/policyengine_api/gcp_logging.py +++ b/policyengine_api/gcp_logging.py @@ -1,3 +1,11 @@ -from google.cloud.logging import Client +import os -logger = Client().logger("policyengine-api") +if os.getenv("ENV") == "local": + import logging + + logger = logging.getLogger("local-logger") + logger.warning("Using local logger (GCP logging disabled)") +else: + from google.cloud.logging import Client + + logger = Client().logger("policyengine-api") diff --git a/policyengine_api/routes/user_profile_routes.py b/policyengine_api/routes/user_profile_routes.py index d859629c6..cb2dbc5fe 100644 --- a/policyengine_api/routes/user_profile_routes.py +++ b/policyengine_api/routes/user_profile_routes.py @@ -4,6 +4,7 @@ import json from policyengine_api.services.user_service import UserService from werkzeug.exceptions import BadRequest, NotFound +import time user_profile_bp = Blueprint("user_profile", __name__) user_service = UserService() @@ -64,7 +65,12 @@ def get_user_profile(country_id: str) -> Response: ) if row is None: - raise NotFound("No such user") + _, row = user_service.create_profile( + primary_country=country_id, + auth0_id=auth0_id if auth0_id is not None else "", + username=None, + user_since=str(int(time.time())), + ) readable_row = dict(row) # Delete auth0_id value if querying from user_id, as that value From d1f533b1e64f14085fd223f1bd04a28c765b31c4 Mon Sep 17 00:00:00 2001 From: v-lerie Date: Mon, 23 Jun 2025 00:44:06 -0400 Subject: [PATCH 2/2] Added changelog_entry --- changelog_entry.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29bb..615e3320f 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,5 @@ +- bump: patch + changes: + added: + - Automatically create a user profile if none exists when fetching by auth0_id in the user-profile GET endpoint. + - Conditional logging setup in `gcp_logging.py` to use a local logger when `ENV=local`, disabling Google Cloud logging for local development.