From 360a0435e847fcf268ba8542cedf9dd1048d4194 Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Tue, 12 May 2026 19:09:44 -0400 Subject: [PATCH] Fix shared layer structure and DynamoDB Decimal type error (#2) Move shared layer source from src/shared/python/shared/ to src/shared/shared/ to prevent SAM from creating a double python/python/ directory in the layer artifact. Add _to_decimal() helper to convert floats to Decimal for DynamoDB compatibility in put_order. --- src/shared/{python => }/shared/__init__.py | 0 src/shared/{python => }/shared/db.py | 11 +++++++++-- src/shared/{python => }/shared/secrets.py | 0 src/shared/{python => }/shared/slack.py | 0 4 files changed, 9 insertions(+), 2 deletions(-) rename src/shared/{python => }/shared/__init__.py (100%) rename src/shared/{python => }/shared/db.py (92%) rename src/shared/{python => }/shared/secrets.py (100%) rename src/shared/{python => }/shared/slack.py (100%) diff --git a/src/shared/python/shared/__init__.py b/src/shared/shared/__init__.py similarity index 100% rename from src/shared/python/shared/__init__.py rename to src/shared/shared/__init__.py diff --git a/src/shared/python/shared/db.py b/src/shared/shared/db.py similarity index 92% rename from src/shared/python/shared/db.py rename to src/shared/shared/db.py index 6129801..7d0099e 100644 --- a/src/shared/python/shared/db.py +++ b/src/shared/shared/db.py @@ -1,6 +1,8 @@ +import json import os import time from datetime import datetime +from decimal import Decimal from zoneinfo import ZoneInfo from boto3.dynamodb.conditions import Key import boto3 @@ -63,8 +65,13 @@ def get_form_status(week: str) -> str: return menu.get("form_status", "closed") +def _to_decimal(obj): + """Convert floats to Decimal for DynamoDB compatibility.""" + return json.loads(json.dumps(obj), parse_float=Decimal) + + def put_order(week: str, employee_slug: str, order_data: dict): - _get_table().put_item(Item={ + _get_table().put_item(Item=_to_decimal({ "PK": f"WEEK#{week}", "SK": f"ORDER#{employee_slug}", "employee_name": order_data["employee_name"], @@ -73,7 +80,7 @@ def put_order(week: str, employee_slug: str, order_data: dict): "items": order_data["items"], "total": order_data["total"], "ttl": ttl_days(90), - }) + })) def get_orders(week: str) -> list[dict]: diff --git a/src/shared/python/shared/secrets.py b/src/shared/shared/secrets.py similarity index 100% rename from src/shared/python/shared/secrets.py rename to src/shared/shared/secrets.py diff --git a/src/shared/python/shared/slack.py b/src/shared/shared/slack.py similarity index 100% rename from src/shared/python/shared/slack.py rename to src/shared/shared/slack.py