Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 10 additions & 2 deletions policyengine_api/gcp_logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from google.cloud.logging import Client
import os
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: I believe this code is bleed-over from another PR.

Please remove so that we can keep those changes isolated to their own PR.


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")
8 changes: 7 additions & 1 deletion policyengine_api/routes/user_profile_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: I don't think this is the behavior we want here

Ideally, we should raise a NotFound when a user doesn't exist, thereby returning a 404

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
Expand Down
Loading