Skip to content

Difference between sync_to_async vs. database_sync_to_async #2073

Discussion options

You must be logged in to vote

Hi @keithhackbarth,

database_sync_to_async() literally just wraps sync_to_async() with a call to Django's (internal) clean up function close_old_connections().

Django itself calls that for each request when dispatching the request_finised signal.

So, if you're running your requests through to Django, likely you'll not need to call it yourself. For requests which go only to Channels consumers, and make use of the database, you likely should use database_sync_to_async().

Make sense?

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@keithhackbarth
Comment options

@carltongibson
Comment options

Answer selected by keithhackbarth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants