Optional / Possibly Missing Dict Keys¶
This note tracks places where plain DynamoDB/API dictionaries can produce missing-key bugs. It is intentionally line-number-free because these hotspots move often.
Current Risk Areas¶
Area |
Risk |
Notes |
|---|---|---|
User primary course |
High |
Upload and page-context code assumes |
Movie access |
High |
Direct movie access checks must match movie-list visibility: owner, admin, or published course-visible movie. |
Movie artifact URNs |
Medium |
|
Lambda queue messages |
Medium |
Local/SQS messages are dicts with |
Boto3 responses |
Low |
DynamoDB/S3 response shapes are external dict contracts. Use |
Current Model Boundary¶
src/app/schema.py defines Pydantic models for writes and validation:
UserCourseApiKeyMovieMovieFrameTrackpointLogEntry
Most read paths still return plain dicts from DynamoDB. That keeps boto3 usage simple but weakens static checking and encourages repeated string keys.
Recommended Direction¶
Short term:
Keep validating writes with the existing Pydantic models.
Add targeted
.get()guards for genuinely optional fields.Keep all dict keys in named constants when external APIs force dicts.
Medium term:
Add Pydantic request/response models for Flask API and Lambda queue payloads.
Convert high-risk return paths (
get_user,get_movie, movie metadata) to typed DTOs or Pydantic models.Keep DynamoDB adapter code responsible for converting Decimal and absent values into model-friendly Python values.
Long term:
Make repository/service boundaries return typed models.
Keep dicts at external boundaries only: Flask form data, JSON bodies, boto3 requests/responses, and S3 metadata.