GET /api/events/by_org/<org_id> returns 500 for orgs with imported calendar events #59

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

What's wrong
event_to_dict() inside get_events_by_organization() reads ev.all_day and ev.updated_at. The Event model has is_all_day and last_updated_at, so the route raises AttributeError for any org with at least one event linked to one of its calendar sources (any org that imported an iCal feed). The route has no try/except, so Flask returns its own 500. Orgs without such events get {"events": []}.

How to reproduce
Pick an org that has imported an iCal feed:

curl -i http://localhost:5001/api/events/by_org/<org_id>

In tests: event_factory(org=..., category=..., calendar_source_id=world["cs1"], user_edited=None), then GET /api/events/by_org/{world["org1"]}.

Expected
200 with the events. Keep the JSON keys all_day and updated_at so callers do not break; read them from is_all_day and last_updated_at.

Where to look

  • api/app/api/events.py get_events_by_organization() (L971-999), attributes at L993 and L996.
  • api/app/models/models.py class Event for the real column names.
  • Note: the route only returns events with a calendar source (it joins on CalendarSource.org_id), and the web client does not call it today.
  • Line numbers are from main at 2c5f2e9.

Done when

  • the route returns 200 for an org with calendar-imported events
  • test in api/tests/api/test_events_by_org.py covering that org and an org with none
**What's wrong** `event_to_dict()` inside `get_events_by_organization()` reads `ev.all_day` and `ev.updated_at`. The `Event` model has `is_all_day` and `last_updated_at`, so the route raises AttributeError for any org with at least one event linked to one of its calendar sources (any org that imported an iCal feed). The route has no try/except, so Flask returns its own 500. Orgs without such events get `{"events": []}`. **How to reproduce** Pick an org that has imported an iCal feed: ``` curl -i http://localhost:5001/api/events/by_org/<org_id> ``` In tests: `event_factory(org=..., category=..., calendar_source_id=world["cs1"], user_edited=None)`, then GET `/api/events/by_org/{world["org1"]}`. **Expected** 200 with the events. Keep the JSON keys `all_day` and `updated_at` so callers do not break; read them from `is_all_day` and `last_updated_at`. **Where to look** - `api/app/api/events.py` `get_events_by_organization()` (L971-999), attributes at L993 and L996. - `api/app/models/models.py` `class Event` for the real column names. - Note: the route only returns events with a calendar source (it joins on `CalendarSource.org_id`), and the web client does not call it today. - Line numbers are from main at 2c5f2e9. **Done when** - [ ] the route returns 200 for an org with calendar-imported events - [ ] test in `api/tests/api/test_events_by_org.py` covering that org and an org with none
jalenluorion added this to the Phase 1 milestone 2026-10-03 19:44:42 +00:00
jalenluorion added this to the CMUCal project 2026-10-03 19:45:09 +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#59
No description provided.