From ec9004728ee136e3b7e2b7cd2610203e16b6ce9b Mon Sep 17 00:00:00 2001 From: Caio Ariede Date: Wed, 5 Aug 2015 11:08:56 -0300 Subject: [PATCH] Fixed #25175 -- Renamed the postgresql_psycopg2 database backend to postgresql. --- django/contrib/gis/db/backends/postgis/base.py | 2 +- .../contrib/gis/db/backends/postgis/features.py | 2 +- .../gis/db/backends/postgis/introspection.py | 3 +-- .../gis/db/backends/postgis/operations.py | 3 +-- django/contrib/gis/db/backends/postgis/schema.py | 2 +- .../__init__.py | 0 .../{postgresql_psycopg2 => postgresql}/base.py | 0 .../client.py | 0 .../creation.py | 0 .../features.py | 0 .../introspection.py | 0 .../operations.py | 0 .../schema.py | 0 .../{postgresql_psycopg2 => postgresql}/utils.py | 0 .../version.py | 0 django/db/utils.py | 12 ++++++++++-- docs/intro/tutorial02.txt | 2 +- docs/ref/models/querysets.txt | 2 +- docs/ref/settings.txt | 16 ++++++++++------ docs/ref/signals.txt | 2 +- docs/releases/1.9.txt | 7 +++++++ docs/topics/db/multi-db.txt | 2 +- tests/backends/test_utils.py | 2 +- tests/backends/tests.py | 8 ++++---- tests/dbshell/test_postgresql_psycopg2.py | 2 +- 25 files changed, 42 insertions(+), 25 deletions(-) rename django/db/backends/{postgresql_psycopg2 => postgresql}/__init__.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/base.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/client.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/creation.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/features.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/introspection.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/operations.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/schema.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/utils.py (100%) rename django/db/backends/{postgresql_psycopg2 => postgresql}/version.py (100%) diff --git a/django/contrib/gis/db/backends/postgis/base.py b/django/contrib/gis/db/backends/postgis/base.py index fc8a16d97f..203e3ba075 100644 --- a/django/contrib/gis/db/backends/postgis/base.py +++ b/django/contrib/gis/db/backends/postgis/base.py @@ -1,5 +1,5 @@ from django.db.backends.base.base import NO_DB_ALIAS -from django.db.backends.postgresql_psycopg2.base import \ +from django.db.backends.postgresql.base import \ DatabaseWrapper as Psycopg2DatabaseWrapper from .features import DatabaseFeatures diff --git a/django/contrib/gis/db/backends/postgis/features.py b/django/contrib/gis/db/backends/postgis/features.py index 3fad9e70c0..ea1d450008 100644 --- a/django/contrib/gis/db/backends/postgis/features.py +++ b/django/contrib/gis/db/backends/postgis/features.py @@ -1,5 +1,5 @@ from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures -from django.db.backends.postgresql_psycopg2.features import \ +from django.db.backends.postgresql.features import \ DatabaseFeatures as Psycopg2DatabaseFeatures diff --git a/django/contrib/gis/db/backends/postgis/introspection.py b/django/contrib/gis/db/backends/postgis/introspection.py index 7f231a578a..71aa57f163 100644 --- a/django/contrib/gis/db/backends/postgis/introspection.py +++ b/django/contrib/gis/db/backends/postgis/introspection.py @@ -1,6 +1,5 @@ from django.contrib.gis.gdal import OGRGeomType -from django.db.backends.postgresql_psycopg2.introspection import \ - DatabaseIntrospection +from django.db.backends.postgresql.introspection import DatabaseIntrospection class GeoIntrospectionError(Exception): diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py index 31406e6506..e5bb115b71 100644 --- a/django/contrib/gis/db/backends/postgis/operations.py +++ b/django/contrib/gis/db/backends/postgis/operations.py @@ -11,8 +11,7 @@ from django.contrib.gis.db.backends.utils import SpatialOperator from django.contrib.gis.geometry.backend import Geometry from django.contrib.gis.measure import Distance from django.core.exceptions import ImproperlyConfigured -from django.db.backends.postgresql_psycopg2.operations import \ - DatabaseOperations +from django.db.backends.postgresql.operations import DatabaseOperations from django.db.utils import ProgrammingError from django.utils.functional import cached_property diff --git a/django/contrib/gis/db/backends/postgis/schema.py b/django/contrib/gis/db/backends/postgis/schema.py index 8c2cb38608..8b4444b213 100644 --- a/django/contrib/gis/db/backends/postgis/schema.py +++ b/django/contrib/gis/db/backends/postgis/schema.py @@ -1,4 +1,4 @@ -from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor +from django.db.backends.postgresql.schema import DatabaseSchemaEditor class PostGISSchemaEditor(DatabaseSchemaEditor): diff --git a/django/db/backends/postgresql_psycopg2/__init__.py b/django/db/backends/postgresql/__init__.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/__init__.py rename to django/db/backends/postgresql/__init__.py diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql/base.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/base.py rename to django/db/backends/postgresql/base.py diff --git a/django/db/backends/postgresql_psycopg2/client.py b/django/db/backends/postgresql/client.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/client.py rename to django/db/backends/postgresql/client.py diff --git a/django/db/backends/postgresql_psycopg2/creation.py b/django/db/backends/postgresql/creation.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/creation.py rename to django/db/backends/postgresql/creation.py diff --git a/django/db/backends/postgresql_psycopg2/features.py b/django/db/backends/postgresql/features.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/features.py rename to django/db/backends/postgresql/features.py diff --git a/django/db/backends/postgresql_psycopg2/introspection.py b/django/db/backends/postgresql/introspection.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/introspection.py rename to django/db/backends/postgresql/introspection.py diff --git a/django/db/backends/postgresql_psycopg2/operations.py b/django/db/backends/postgresql/operations.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/operations.py rename to django/db/backends/postgresql/operations.py diff --git a/django/db/backends/postgresql_psycopg2/schema.py b/django/db/backends/postgresql/schema.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/schema.py rename to django/db/backends/postgresql/schema.py diff --git a/django/db/backends/postgresql_psycopg2/utils.py b/django/db/backends/postgresql/utils.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/utils.py rename to django/db/backends/postgresql/utils.py diff --git a/django/db/backends/postgresql_psycopg2/version.py b/django/db/backends/postgresql/version.py similarity index 100% rename from django/db/backends/postgresql_psycopg2/version.py rename to django/db/backends/postgresql/version.py diff --git a/django/db/utils.py b/django/db/utils.py index 64d44a715b..380a4b9554 100644 --- a/django/db/utils.py +++ b/django/db/utils.py @@ -104,7 +104,14 @@ class DatabaseErrorWrapper(object): def load_backend(backend_name): - # Look for a fully qualified database backend name + """ + Return a database backend's "base" module given a fully qualified database + backend name, or raise an error if it doesn't exist. + """ + # This backend was renamed in Django 1.9. + if backend_name == 'django.db.backends.postgresql_psycopg2': + backend_name = 'django.db.backends.postgresql' + try: return import_module('%s.base' % backend_name) except ImportError as e_user: @@ -114,7 +121,8 @@ def load_backend(backend_name): try: builtin_backends = [ name for _, name, ispkg in pkgutil.iter_modules([npath(backend_dir)]) - if ispkg and name not in {'base', 'dummy'}] + if ispkg and name not in {'base', 'dummy', 'postgresql_psycopg2'} + ] except EnvironmentError: builtin_backends = [] if backend_name not in ['django.db.backends.%s' % b for b in diff --git a/docs/intro/tutorial02.txt b/docs/intro/tutorial02.txt index e1dd7d0bc7..049d33c1f1 100644 --- a/docs/intro/tutorial02.txt +++ b/docs/intro/tutorial02.txt @@ -26,7 +26,7 @@ settings: * :setting:`ENGINE ` -- Either ``'django.db.backends.sqlite3'``, - ``'django.db.backends.postgresql_psycopg2'``, + ``'django.db.backends.postgresql'``, ``'django.db.backends.mysql'``, or ``'django.db.backends.oracle'``. Other backends are :ref:`also available `. diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index f21887c6bd..47a75ddfc6 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1512,7 +1512,7 @@ make the call non-blocking. If a conflicting lock is already acquired by another transaction, :exc:`~django.db.DatabaseError` will be raised when the queryset is evaluated. -Currently, the ``postgresql_psycopg2``, ``oracle``, and ``mysql`` database +Currently, the ``postgresql``, ``oracle``, and ``mysql`` database backends support ``select_for_update()``. However, MySQL has no support for the ``nowait`` argument. Obviously, users of external third-party backends should check with their backend's documentation for specifics in those cases. diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index 1077b910f2..eccba53274 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -459,7 +459,7 @@ other database types. This example is for PostgreSQL:: DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydatabase', 'USER': 'mydatabaseuser', 'PASSWORD': 'mypassword', @@ -500,14 +500,19 @@ Default: ``''`` (Empty string) The database backend to use. The built-in database backends are: -* ``'django.db.backends.postgresql_psycopg2'`` +* ``'django.db.backends.postgresql'`` * ``'django.db.backends.mysql'`` * ``'django.db.backends.sqlite3'`` * ``'django.db.backends.oracle'`` You can use a database backend that doesn't ship with Django by setting -``ENGINE`` to a fully-qualified path (i.e. -``mypackage.backends.whatever``). +``ENGINE`` to a fully-qualified path (i.e. ``mypackage.backends.whatever``). + +.. versionchanged:: 1.9 + + The ``django.db.backends.postgresql`` backend is named + ``django.db.backends.postgresql_psycopg2`` in older releases. For backwards + compatibility, the old name still works in newer versions. .. setting:: HOST @@ -657,8 +662,7 @@ The character set encoding used to create the test database. The value of this string is passed directly through to the database, so its format is backend-specific. -Supported for the PostgreSQL_ (``postgresql_psycopg2``) and MySQL_ (``mysql``) -backends. +Supported by the PostgreSQL_ (``postgresql``) and MySQL_ (``mysql``) backends. .. _PostgreSQL: http://www.postgresql.org/docs/current/static/multibyte.html .. _MySQL: http://dev.mysql.com/doc/refman/5.6/en/charset-database.html diff --git a/docs/ref/signals.txt b/docs/ref/signals.txt index 1636fee9fc..aa85904843 100644 --- a/docs/ref/signals.txt +++ b/docs/ref/signals.txt @@ -625,7 +625,7 @@ Arguments sent with this signal: ``sender`` The database wrapper class -- i.e. - ``django.db.backends.postgresql_psycopg2.DatabaseWrapper`` or + ``django.db.backends.postgresql.DatabaseWrapper`` or ``django.db.backends.mysql.DatabaseWrapper``, etc. ``connection`` diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index 1f1183d9a7..5d017b3042 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -578,6 +578,13 @@ Validators * Added :func:`~django.core.validators.validate_unicode_slug` to validate slugs that may contain Unicode characters. +Database backends +^^^^^^^^^^^^^^^^^ + +* The PostgreSQL backend (``django.db.backends.postgresql_psycopg2``) is also + available as ``django.db.backends.postgresql``. The old name will continue to + be available for backwards compatibility. + Backwards incompatible changes in 1.9 ===================================== diff --git a/docs/topics/db/multi-db.txt b/docs/topics/db/multi-db.txt index 6b4f6a0a66..fca21388c9 100644 --- a/docs/topics/db/multi-db.txt +++ b/docs/topics/db/multi-db.txt @@ -29,7 +29,7 @@ databases -- a default PostgreSQL database and a MySQL database called DATABASES = { 'default': { 'NAME': 'app_data', - 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'ENGINE': 'django.db.backends.postgresql', 'USER': 'postgres_user', 'PASSWORD': 's3krit' }, diff --git a/tests/backends/test_utils.py b/tests/backends/test_utils.py index beec31d2f5..6f59d1b23b 100644 --- a/tests/backends/test_utils.py +++ b/tests/backends/test_utils.py @@ -9,7 +9,7 @@ class TestLoadBackend(SimpleTestCase): msg = ( "'foo' isn't an available database backend.\n" "Try using 'django.db.backends.XXX', where XXX is one of:\n" - " 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'\n" + " 'mysql', 'oracle', 'postgresql', 'sqlite3'\n" "Error was: No module named %s" ) % "foo.base" if six.PY2 else "'foo'" with self.assertRaisesMessage(ImproperlyConfigured, msg): diff --git a/tests/backends/tests.py b/tests/backends/tests.py index fc62c6587c..b918be3e51 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -18,7 +18,7 @@ from django.db import ( reset_queries, transaction, ) from django.db.backends.base.base import BaseDatabaseWrapper -from django.db.backends.postgresql_psycopg2 import version as pg_version +from django.db.backends.postgresql import version as pg_version from django.db.backends.signals import connection_created from django.db.backends.utils import CursorWrapper, format_number from django.db.models import Avg, StdDev, Sum, Variance @@ -313,7 +313,7 @@ class PostgreSQLTests(TestCase): self.assertEqual(a[0], b[0]) def test_lookup_cast(self): - from django.db.backends.postgresql_psycopg2.operations import DatabaseOperations + from django.db.backends.postgresql.operations import DatabaseOperations do = DatabaseOperations(connection=None) for lookup in ('iexact', 'contains', 'icontains', 'startswith', @@ -321,8 +321,8 @@ class PostgreSQLTests(TestCase): self.assertIn('::text', do.lookup_cast(lookup)) def test_correct_extraction_psycopg2_version(self): - from django.db.backends.postgresql_psycopg2.base import psycopg2_version - version_path = 'django.db.backends.postgresql_psycopg2.base.Database.__version__' + from django.db.backends.postgresql.base import psycopg2_version + version_path = 'django.db.backends.postgresql.base.Database.__version__' with mock.patch(version_path, '2.6.9'): self.assertEqual(psycopg2_version(), (2, 6, 9)) diff --git a/tests/dbshell/test_postgresql_psycopg2.py b/tests/dbshell/test_postgresql_psycopg2.py index 0bb8721b70..f74ea3ddb2 100644 --- a/tests/dbshell/test_postgresql_psycopg2.py +++ b/tests/dbshell/test_postgresql_psycopg2.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import locale import os -from django.db.backends.postgresql_psycopg2.client import DatabaseClient +from django.db.backends.postgresql.client import DatabaseClient from django.test import SimpleTestCase, mock from django.utils import six from django.utils.encoding import force_bytes, force_str