Skip to content

Org events page shows an error for empty organizations due to inconsistent API response format #2348

Description

@Ayananth

Terms

Behavior

Summary

The bug is caused by an inconsistent response format from the organization events API.

When an organization has no events, the API returns a paginated object containing { results: [ ] }, while an organization with events returns a plain array. The frontend always calls .map() directly on the response, causing the events page to crash for organizations with no events.

Error

res.map is not a function

Screenshot

Image

Steps to reproduce

  1. Create a new organization with no events.
  2. Visit /organizations/<orgId>/events.
  3. The page shows error.

Root cause

Backend

OrganizationEventViewSet.list() in backend/communities/organizations/views.py returns different response shapes depending on whether events exist:

  • No events:

    {
      "count": 0,
      "next": null,
      "previous": null,
      "results": []
    }
  • Has events:

    [...]

Frontend

fetchOrganizationEvents() in frontend/app/services/communities/organization/event.ts always expects a plain array:

return res.map(mapEvent);

When the organization has no events, res is an object rather than an array, causing:

res.map is not a function

Contribution

What would you prefer as the fix here: handling the response shape in the frontend, or making the backend return a consistent response format? I'm happy to work on either approach.

I'm happy to open a PR for the fix once this issue is confirmed.

Metadata

Metadata

Assignees

Labels

-priority-High prioritybackendRelates to the project backendfrontendRelates to the project frontendtypescriptRelates to TypeScript codevueRelates to Vue code

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions