Saving an event returns 500 for a second user, a repeat save, or no google_event_id #35

Open
opened 2026-10-03 19:44:37 +00:00 by jalenluorion · 0 comments
Member

What's wrong
POST /api/events/user_saved_events inserts a UserSavedEvent with google_event_id=data["google_event_id"]. That column is NOT NULL and globally UNIQUE (user_saved_events_google_event_id_key), and the web client fills it with the CMUCal event id (web/src/context/EventStateContext.tsx L104-107, marked TODO). Results:

  • once one user saves event 42, any other user saving event 42 hits the unique constraint: 500;
  • saving the same event twice violates the (user_id, event_id) primary key: 500;
  • leaving out google_event_id raises KeyError: 500;
  • an unknown event_id violates the foreign key on Postgres: 500.

The web client swallows the error, so the event looks saved but is not stored. Nothing reads UserSavedEvent.google_event_id; Google sync is tracked in synced_events.

How to reproduce
In a test, POST {"event_id": <id>, "google_event_id": "<id>"} as ALICE, then the same body as BOB: the second call returns 500. POST without google_event_id: 500.

Expected

  • Any user can save any event; a repeat save is a 200 no-op.
  • google_event_id is optional; an unknown event returns 404.

Where to look

  • api/app/api/events.py user_save_event() (L915-934).
  • api/app/models/models.py class UserSavedEvent; new Alembic migration in api/migrations/versions/ to make the column nullable and drop the global unique constraint.
  • Line numbers are from main at 2c5f2e9.

Done when

  • migration plus route fix
  • tests in api/tests/api/test_user_saved_events.py: two users save one event, a repeat save, no google_event_id, an unknown event
  • follow-up noted for the web team to stop sending google_event_id
**What's wrong** `POST /api/events/user_saved_events` inserts a `UserSavedEvent` with `google_event_id=data["google_event_id"]`. That column is NOT NULL and globally UNIQUE (`user_saved_events_google_event_id_key`), and the web client fills it with the CMUCal event id (`web/src/context/EventStateContext.tsx` L104-107, marked TODO). Results: - once one user saves event 42, any other user saving event 42 hits the unique constraint: 500; - saving the same event twice violates the (user_id, event_id) primary key: 500; - leaving out `google_event_id` raises KeyError: 500; - an unknown `event_id` violates the foreign key on Postgres: 500. The web client swallows the error, so the event looks saved but is not stored. Nothing reads `UserSavedEvent.google_event_id`; Google sync is tracked in `synced_events`. **How to reproduce** In a test, POST `{"event_id": <id>, "google_event_id": "<id>"}` as `ALICE`, then the same body as `BOB`: the second call returns 500. POST without `google_event_id`: 500. **Expected** - Any user can save any event; a repeat save is a 200 no-op. - `google_event_id` is optional; an unknown event returns 404. **Where to look** - `api/app/api/events.py` `user_save_event()` (L915-934). - `api/app/models/models.py` `class UserSavedEvent`; new Alembic migration in `api/migrations/versions/` to make the column nullable and drop the global unique constraint. - Line numbers are from main at 2c5f2e9. **Done when** - [ ] migration plus route fix - [ ] tests in `api/tests/api/test_user_saved_events.py`: two users save one event, a repeat save, no `google_event_id`, an unknown event - [ ] follow-up noted for the web team to stop sending `google_event_id`
jalenluorion added this to the Phase 1 milestone 2026-10-03 19:44:37 +00:00
jalenluorion added this to the CMUCal project 2026-10-03 19:45:09 +00:00
naemii self-assigned this 2026-11-07 21:24:36 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ScottyLabs/cal#35
No description provided.