OWASP / OWASP/Nest

Blocking synchronous OpenAI calls inside Event.save() cause request latency and failures

Open
#3,502 0 comments 0 reactions 0 assignees View on GitHub
bug enhancement
Dominant language
Python
Stars
451
Forks
707
Avg merge
22h 59m
Merged PRs (30d)
91

Description

## Describe the bug

The `Event.save()` method performs **synchronous OpenAI API calls** via `generate_suggested_location()` and `generate_summary()`.
These methods instantiate `OpenAi` and call `complete()` during the model save lifecycle, causing the request handling thread/worker to block until the external API responds.

This introduces significant latency and makes event creation or updates tightly coupled to OpenAI availability and response time.

---

## To Reproduce

1. Create or update an `Event` instance that triggers `Event.save()`.
2. Ensure `generate_suggested_location()` and/or `generate_summary()` are executed.
3. Observe the request duration while the OpenAI API call is in progress.
4. If the OpenAI API is slow or unavailable, the request blocks or fails.

---

## Expected behavior

Saving an `Event` should be fast and non-blocking.
AI-generated fields (summary, suggested location) should be computed asynchronously or via a background task, so that:

- Event creation/update does not block on external API calls
- Temporary OpenAI outages do not break core functionality
- Request latency remains predictable

---

## Are you going to work on fixing this?

- [x] Yes
- [ ] No

---

## Screenshots

Not applicable (backend performance/reliability issue).

---

## Desktop

- OS: N/A
- Browser: N/A
- Version: N/A

---

## Smartphone

- Device: N/A
- OS: N/A
- Browser: N/A
- Version: N/A

---

## Additional context

The synchronous OpenAI calls occur inside a Django model `save()` method, which is part of the critical request path.
Offloading these operations to a background task queue (e.g., Celery) or triggering them asynchronously after persistence would significantly improve performance and reliability.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.