• Language: en
  • Documentation version: development

Django 2.0 release notes - UNDER DEVELOPMENT

Welcome to Django 2.0!

These release notes cover the new features, as well as some backwards incompatible changes you’ll want to be aware of when upgrading from Django 1.11 or earlier. We’ve dropped some features that have reached the end of their deprecation cycle, and we’ve begun the deprecation process for some features.

See the Upgrading Django to a newer version guide if you’re updating an existing project.

Python compatibility

Django 2.0 supports Python 3.5+. Since Django 1.11, support for Python 2.7 and 3.4 is removed. We highly recommend and only officially support the latest release of each series.

Third-party library support for older version of Django

Following the release of Django 2.0, we suggest that third-party app authors drop support for all versions of Django prior to 1.11. At that time, you should be able run your package’s tests using python -Wd so that deprecation warnings do appear. After making the deprecation warning fixes, your app should be compatible with Django 2.0.

What’s new in Django 2.0

Minor features

django.contrib.auth

  • The default iteration count for the PBKDF2 password hasher is increased from 36,000 to 100,000.

django.contrib.gis

django.contrib.postgres

  • The new distinct argument for ArrayAgg determines if concatenated values will be distinct.
  • The new RandomUUID database function returns a version 4 UUID. It requires use of PostgreSQL’s pgcrypto extension which can be activated using the new CryptoExtension migration operation.
  • django.contrib.postgres.indexes.GinIndex now supports the fast_update and gin_pending_list_limit parameters.

django.contrib.sitemaps

  • Added the protocol keyword argument to the GenericSitemap constructor.

Cache

CSRF

Database backends

Email

File Storage

  • File.open() can be used as a context manager, e.g. with file.open() as f:.

File Uploads

Forms

Generic Views

Internationalization

Management Commands

  • inspectdb now translates MySQL’s unsigned integer columns to PositiveIntegerField or PositiveSmallIntegerField.
  • The new makemessages --add-location option controls the comment format in PO files.
  • loaddata can now read from stdin.
  • The new diffsettings --output option allows formatting the output in a unified diff format.
  • On Oracle, inspectdb can now introspect AutoField if the column is created as an identity column.
  • On MySQL, dbshell now supports client-side TLS certificates.

Migrations

Models

  • The new StrIndex database function finds the starting index of a string inside another string.
  • On Oracle, AutoField and BigAutoField are now created as identity columns.
  • The new chunk_size parameter of QuerySet.iterator() controls the number of rows fetched by the Python database client when streaming results from the database. For databases that don’t support server-side cursors, it controls the number of results Django fetches from the database adapter.
  • Added the ExtractQuarter function to extract the quarter from DateField and DateTimeField, and exposed it through the quarter lookup.
  • Added the TruncQuarter function to truncate DateField and DateTimeField to the first day of a quarter.

Requests and Responses

  • The runserver Web server supports HTTP 1.1.

Serialization

Signals

Templates

  • To increase the usefulness of Engine.get_default() in third-party apps, it now returns the first engine if multiple DjangoTemplates engines are configured in TEMPLATES rather than raising ImproperlyConfigured.
  • Custom template tags may now accept keyword-only arguments.

Tests

URLs

Validators

Backwards incompatible changes in 2.0

Removed support for bytestrings in some places

To support native Python 2 strings, older Django versions had to accept both bytestrings and unicode strings. Now that Python 2 support is dropped, bytestrings should only be encountered around input/output boundaries (handling of binary fields or HTTP streams, for example). You might have to update your code to limit bytestring usage to a minimum, as Django no longer accepts bytestrings in certain code paths.

Database backend API

This section describes changes that may be needed in third-party database backends.

  • The DatabaseOperations.datetime_cast_date_sql(), datetime_cast_time_sql(), datetime_trunc_sql(), and datetime_extract_sql() methods now return only the SQL to perform the operation instead of SQL and a list of parameters.
  • Third-party database backends should add a DatabaseWrapper.display_name attribute with the name of the database that your backend works with. Django may use it in various messages, such as in system checks.
  • The first argument of SchemaEditor._alter_column_type_sql() is now model rather than table.
  • The first argument of SchemaEditor._create_index_name() is now table_name rather than model.

Dropped support for Oracle 11.2

The end of upstream support for Oracle 11.2 is Dec. 2020. Django 1.11 will be supported until April 2020 which almost reaches this date. Django 2.0 officially supports Oracle 12.1+.

Default MySQL isolation level is read committed

MySQL’s default isolation level, repeatable read, may cause data loss in typical Django usage. To prevent that and for consistency with other databases, the default isolation level is now read committed. You can use the DATABASES setting to use a different isolation level, if needed.

AbstractUser.last_name max_length increased to 150

A migration for django.contrib.auth.models.User.last_name is included. If you have a custom user model inheriting from AbstractUser, you’ll need to generate and apply a database migration for your user model.

If you want to preserve the 30 character limit for last names, use a custom form:

from django.contrib.auth.forms import UserChangeForm

class MyUserChangeForm(UserChangeForm):
    last_name = forms.CharField(max_length=30, required=False)

If you wish to keep this restriction in the admin when editing users, set UserAdmin.form to use this form:

from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

class MyUserAdmin(UserAdmin):
    form = MyUserChangeForm

admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)

QuerySet.reverse() and last() are prohibited after slicing

Calling QuerySet.reverse() or last() on a sliced queryset leads to unexpected results due to the slice being applied after reordering. This is now prohibited, e.g.:

>>> Model.objects.all()[:2].reverse()
Traceback (most recent call last):
...
TypeError: Cannot reverse a query once a slice has been taken.

Form fields no longer accept optional arguments as positional arguments

To help prevent runtime errors due to incorrect ordering of form field arguments, optional arguments of built-in form fields are no longer accepted as positional arguments. For example:

forms.IntegerField(25, 10)

raises an exception and should be replaced with:

forms.IntegerField(max_value=25, min_value=10)

call_command() validates the options it receives

call_command() now validates that the argument parser of the command being called defines all of the options passed to call_command().

For custom management commands that use options not created using parser.add_argument(), add a stealth_options attribute on the command:

class MyCommand(BaseCommand):
    stealth_options = ('option_name', ...)

Miscellaneous

  • The SessionAuthenticationMiddleware class is removed. It provided no functionality since session authentication is unconditionally enabled in Django 1.10.

  • The default HTTP error handlers (handler404, etc.) are now callables instead of dotted Python path strings. Django favors callable references since they provide better performance and debugging experience.

  • RedirectView no longer silences NoReverseMatch if the pattern_name doesn’t exist.

  • When USE_L10N is off, FloatField and DecimalField now respect DECIMAL_SEPARATOR and THOUSAND_SEPARATOR during validation. For example, with the settings:

    USE_L10N = False
    USE_THOUSAND_SEPARATOR = True
    DECIMAL_SEPARATOR = ','
    THOUSAND_SEPARATOR = '.'
    

    an input of "1.345" is now converted to 1345 instead of 1.345.

  • Subclasses of AbstractBaseUser are no longer required to implement get_short_name() and get_full_name(). (The base implementations that raise NotImplementedError are removed.) django.contrib.admin uses these methods if implemented but doesn’t require them. Third-party apps that use these methods may want to adopt a similar approach.

  • The FIRST_DAY_OF_WEEK and NUMBER_GROUPING format settings are now kept as integers in JavaScript and JSON i18n view outputs.

  • assertNumQueries() now ignores connection configuration queries. Previously, if a test opened a new database connection, those queries could be included as part of the assertNumQueries() count.

  • The PASSWORD_RESET_TIMEOUT_DAYS setting is more properly respected in contrib.auth password reset. Previously, resets were allowed for one day longer than expected. For example, with the default of PASSWORD_RESET_TIMEOUT_DAYS = 3, password reset tokens are now valid for 72 hours rather than 96 hours.

  • The default size of the Oracle test tablespace is increased from 20M to 50M and the default autoextend size is increased from 10M to 25M.

  • To improve performance when streaming large result sets from the database, QuerySet.iterator() now fetches 2000 rows at a time instead of 100. The old behavior can be restored using the chunk_size parameter. For example:

    Book.objects.iterator(chunk_size=100)
    
  • Providing unknown package names in the packages argument of the JavaScriptCatalog view now raises ValueError instead of passing silently.

  • A model instance’s primary key now appears in the default Model.__str__() method, e.g. Question object (1).

  • makemigrations now detects changes to the model field limit_choices_to option. Add this to your existing migrations or accept an auto-generated migration for fields that use it.

  • Performing queries that require automatic spatial transformations now raises NotImplementedError on MySQL instead of silently using non-transformed geometries.

Features deprecated in 2.0

Miscellaneous

  • The django.db.backends.postgresql_psycopg2 module is deprecated in favor of django.db.backends.postgresql. It’s been an alias since Django 1.9. This only affects code that imports from the module directly. The DATABASES setting can still use 'django.db.backends.postgresql_psycopg2', though you can simplify that by using the 'django.db.backends.postgresql' name added in Django 1.9.
  • django.shortcuts.render_to_response() is deprecated in favor of django.shortcuts.render(). render() takes the same arguments except that is also requires a request.
  • The DEFAULT_CONTENT_TYPE setting is deprecated. It doesn’t interact well well with third-party apps and is obsolete since HTML5 has mostly superseded XHTML.
  • HttpRequest.xreadlines() is deprecated in favor of iterating over the request.

Features removed in 2.0

These features have reached the end of their deprecation cycle and are removed in Django 2.0. See Features deprecated in 1.9 and Features deprecated in 1.10 for details, including how to remove usage of these features.

  • The weak argument to django.dispatch.signals.Signal.disconnect() is removed.
  • django.db.backends.base.BaseDatabaseOperations.check_aggregate_support() is removed.
  • The django.forms.extras package is removed.
  • The assignment_tag helper is removed.
  • The host argument to SimpleTestCase.assertsRedirects() is removed. The compatibility layer which allows absolute URLs to be considered equal to relative ones when the path is identical is also removed.
  • Field.rel and Field.remote_field.to are removed.
  • The on_delete argument for ForeignKey and OneToOneField are now required.
  • django.db.models.fields.add_lazy_relation() is removed.
  • When time zone support is enabled, database backends that don’t support time zones no longer convert aware datetimes to naive values in UTC anymore when such values are passed as parameters to SQL queries executed outside of the ORM, e.g. with cursor.execute().
  • django.contrib.auth.tests.utils.skipIfCustomUser() is removed.
  • The GeoManager and GeoQuerySet classes are removed.
  • The django.contrib.gis.geoip module is removed.
  • The supports_recursion check for template loaders is removed from:
    • django.template.engine.Engine.find_template()
    • django.template.loader_tags.ExtendsNode.find_template()
    • django.template.loaders.base.Loader.supports_recursion()
    • django.template.loaders.cached.Loader.supports_recursion()
  • The load_template and load_template_sources template loader methods are removed.
  • The template_dirs argument for template loaders is removed:
    • django.template.loaders.base.Loader.get_template()
    • django.template.loaders.cached.Loader.cache_key()
    • django.template.loaders.cached.Loader.get_template()
    • django.template.loaders.cached.Loader.get_template_sources()
    • django.template.loaders.filesystem.Loader.get_template_sources()
  • django.template.loaders.base.Loader.__call__() is removed.
  • Support for custom error views that don’t accept an exception parameter is removed.
  • The mime_type attribute of django.utils.feedgenerator.Atom1Feed and django.utils.feedgenerator.RssFeed is removed.
  • The app_name argument to include() is removed.
  • Support for passing a 3-tuple (including admin.site.urls) as the first argument to include() is removed.
  • Support for setting a URL instance namespace without an application namespace is removed.
  • Field._get_val_from_obj() is removed.
  • django.template.loaders.eggs.Loader is removed.
  • The current_app parameter to the contrib.auth function-based views is removed.
  • The callable_obj keyword argument to SimpleTestCase.assertRaisesMessage() is removed.
  • Support for the allow_tags attribute on ModelAdmin methods is removed.
  • The enclosure keyword argument to SyndicationFeed.add_item() is removed.
  • The django.template.loader.LoaderOrigin and django.template.base.StringOrigin aliases for django.template.base.Origin are removed.
  • The makemigrations --exit option is removed.
  • Support for direct assignment to a reverse foreign key or many-to-many relation is removed.
  • The get_srid() and set_srid() methods of django.contrib.gis.geos.GEOSGeometry are removed.
  • The get_x(), set_x(), get_y(), set_y(), get_z(), and set_z() methods of django.contrib.gis.geos.Point are removed.
  • The get_coords() and set_coords() methods of django.contrib.gis.geos.Point are removed.
  • The cascaded_union property of django.contrib.gis.geos.MultiPolygon is removed.
  • django.utils.functional.allow_lazy() is removed.
  • The shell --plain option is removed.
  • The django.core.urlresolvers module is removed.
  • CommaSeparatedIntegerField is removed, except for support in historical migrations.
  • The template Context.has_key() method is removed.
  • Support for the django.core.files.storage.Storage.accessed_time(), created_time(), and modified_time() methods is removed.
  • Support for query lookups using the model name when Meta.default_related_name is set is removed.
  • The MySQL __search lookup is removed.
  • The shim for supporting custom related manager classes without a _apply_rel_filters() method is removed.
  • Using User.is_authenticated() and User.is_anonymous() as methods rather than properties is no longer supported.
  • The Model._meta.virtual_fields attribute is removed.
  • The keyword arguments virtual_only in Field.contribute_to_class() and virtual in Model._meta.add_field() are removed.
  • The javascript_catalog() and json_catalog() views are removed.
  • django.contrib.gis.utils.precision_wkt() is removed.
  • In multi-table inheritance, implicit promotion of a OneToOneField to a parent_link is removed.
  • Support for Widget._format_value() is removed.
  • FileField methods get_directory_name() and get_filename() are removed.
  • The mark_for_escaping() function and the classes it uses: EscapeData, EscapeBytes, EscapeText, EscapeString, and EscapeUnicode are removed.
  • The escape filter now uses django.utils.html.conditional_escape().
  • Manager.use_for_related_fields is removed.
  • Model Manager inheritance follows MRO inheritance rules. The requirement to use Meta.manager_inheritance_from_future to opt-in to the behavior is removed.
  • Support for old-style middleware using settings.MIDDLEWARE_CLASSES is removed.
Back to Top