Skip to content

fix(django-cf): stop using DJANGO_ALLOW_ASYNC_UNSAFE from django-cf backends - #230

Open
ryanking13 wants to merge 4 commits into
mainfrom
gyeongjae/d1-do-async-safe
Open

fix(django-cf): stop using DJANGO_ALLOW_ASYNC_UNSAFE from django-cf backends#230
ryanking13 wants to merge 4 commits into
mainfrom
gyeongjae/d1-do-async-safe

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

Stop using discouraged DJANGO_ALLOW_ASYNC_UNSAFE flag and mark django-cf backends async-safe.

Since django by default wraps all the database methods with @async_unsafe decorator, this includes a slightly hacky solution that unwraps decorators of those methods.

@ask-bonk

ask-bonk Bot commented Aug 27, 2026

Copy link
Copy Markdown

LGTM

github run

@dom96 dom96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, isn't this effectively the same as setting DJANGO_ALLOW_ASYNC_UNSAFE?

@ryanking13

Copy link
Copy Markdown
Contributor Author

Hmm, isn't this effectively the same as setting DJANGO_ALLOW_ASYNC_UNSAFE?

Partially, but a few things are different.

  1. There can be other async-unsafe places, e.g. django middlewares or even another database backend (if they are using multiple databases.... though it should be very rare). This change limits the impact only to the django-cf backends to prevent unexpected side effects.

  2. Since the logic it backed in to the database backend itself, users do not need to set the env variable manually. Previously, users need to set it manually or had to inherit DjangoCF class which I don't think is very optimal.

@ryanking13
ryanking13 requested a review from dom96 August 27, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants