Flagsmith / Flagsmith/flagsmith

Sales dashboard: download_org_data 500s with "Object of type generator is not JSON serializable"

Open Beginner friendly
#8,363 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

Sentry: [FLAGSMITH-API-6DT](https://flagsmith.sentry.io/issues/7691629509/)

## What happens

Hitting the sales dashboard org data download endpoint returns a 500. The view passes a generator into `json.dumps`, which Django's JSON encoder cannot serialise, so the download fails outright.

```
TypeError: Object of type generator is not JSON serializable
```

## Where

- **Culprit:** `sales_dashboard/views.py` in `download_org_data`
- **Transaction:** `/sales-dashboard/organisations/{organisation_id}/download_org_data`
- **URL seen:** `http://api.flagsmith.com/sales-dashboard/organisations/33031/download_org_data`

## Stack (app frame in bold context)

```
django/core/handlers/base.py _get_response
django/contrib/auth/decorators.py _view_wrapper
sales_dashboard/views.py download_org_data <-- in app
json/__init__.py dumps
json/encoder.py encode
json/encoder.py iterencode
django/core/serializers/json.py default
json/encoder.py default
```

## Impact

- `isUnhandled: true` — the request 500s, no data is returned
- Events: 1  |  Users affected: 1
- First seen: 2026-08-25 14:50:42 UTC  |  Last seen: 2026-08-25 14:50:42 UTC
- Environment: `production`  |  Host: `ip-172-31-68-88.eu-west-2.compute.internal`

Internal staff tool, so blast radius is limited to the sales dashboard — but the endpoint is currently broken for whoever tries it.

## Likely fix

Materialise the generator (e.g. `list(...)`) before serialising, or stream the response with `StreamingHttpResponse` instead of `json.dumps`.

## Source alert

Slack:

_Filed by automated Sentry triage._

Contributor guide

Open the contributing guide

Research direction

Open sales_dashboard/views.py and inspect download_org_data, then reproduce the failing /sales-dashboard/organisations/{organisation_id}/download_org_data request. Ensure the endpoint no longer passes a generator to JSON serialization, and verify that it returns the organisation data instead of a 500.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.