Django 3.0 is out, and it brings a few new features, most notably its support for asynchronous functionality.

As we reported earlier, a draft proposed to make Django support asynchrony. By focusing on HTTP middleware views and ORM, developers will add asynchronous support to Django, while maintaining support for synchronous Python, and will be fully backward compatible.

This vision will eventually replace most of the blocking parts of Django, including sessions, Auth, ORM and Handlers, with asynchronous support natively. While synchronization apis will continue to exist and be fully supported, some of them will eventually turn into synchronization wrappers for native asynchronous code.

The ASGI pattern runs Django as a native asynchronous application. The old WSGI pattern runs a single event loop around each Django call to make the asynchronous processing layer compatible with the synchronous server.

During this transformation, each feature goes through the following three implementation phases:

  • Sync-only, which only supports synchronization, is the current case
  • Sync-native, with an asynchronous wrapper
  • Async-native, with a synchronous wrapper

Django 3.0 starts with support for running ASGI applications, gradually bringing Django asynchronous capabilities. With this change, Django will now be aware of asynchronous event loops and will prevent calls from an asynchronous context to code marked as “asynchronous unsafe” (such as ORM operations) that might have been triggered if the developer had previously used asynchronous code. If you see a SynchronousOnlyOperation error, take a close look at the code and move the database operation to the synchronized thread.

Among other things, Django now supports MariaDB 10.1 and later; The new ExclusionConstraint class allows you to add exclusion constraints to PostgreSQL. Expressions that output BooleanField can now be used directly in QuerySet filters without annotating and then filtering annotations; Custom enumerated types TextChoices, IntegerChoices, and Choices can now be used as methods to define field. Choices.

There are also some minor changes, see the update notes for details:

  • Docs.djangoproject.com/en/3.0/rele…

Note that Django 3.0 supports Python 3.6, 3.7, and 3.8. The Django 2.2.x series is the last to support Python 3.5. Third-party application authors are also advised to drop support for all versions of Django prior to 2.2.