bug: Chapter.bulk_save() skips location data generation due to save() side effects
- Dominant language
- Python
- Stars
- 451
- Forks
- 702
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 91
Description
**Describe the bug**
`Chapter.save()` contains external API calls (`generate_suggested_location` via OpenAI and `generate_geo_location` via geocoding). Django's `bulk_create`/`bulk_update` bypasses `save()`, so chapters saved via `Chapter.bulk_save()` never get their location data populated — leaving them in an incomplete state silently.
Additionally, even in normal single-object saves, these API calls trigger on every save regardless of whether location-related fields actually changed, causing unnecessary paid API calls.
**To Reproduce**
1. Create or update multiple `Chapter` instances using `Chapter.bulk_save()`
2. Check the saved chapters in DB
3. `suggested_location`, `latitude`, and `longitude` will be `None`/empty even when enough data (country, region, name) is available to generate them
**Expected behavior**
All chapters — whether saved individually or via `bulk_save()` — should have location data populated consistently. External API calls should only be triggered when location-related fields are missing or changed, not on every save.
**Are you going to work on fixing this?**
- [x] Yes
- [ ] No
**Screenshots**
N/A — this is a code-level bug, not a UI issue.
**Desktop (please complete the following information):**
N/A
**Smartphone (please complete the following information):**
N/A
**Additional context**
Root cause: side effects (external API calls) are embedded inside `save()`, which is not called by Django's bulk operations.
Suggested fix: move the API calls out of `save()` and into `update_data()` where they can be called explicitly and conditionally,
This also prevents unnecessary OpenAI and geocoding API calls on unrelated saves.
Contributor guide
Assessment
This issue has not been assessed yet.