Browse Source

Fixed #25175 -- Renamed the postgresql_psycopg2 database backend to postgresql.

Caio Ariede 9 years ago
parent
commit
ec9004728e

+ 1 - 1
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.base.base import NO_DB_ALIAS
-from django.db.backends.postgresql_psycopg2.base import \
+from django.db.backends.postgresql.base import \
     DatabaseWrapper as Psycopg2DatabaseWrapper
     DatabaseWrapper as Psycopg2DatabaseWrapper
 
 
 from .features import DatabaseFeatures
 from .features import DatabaseFeatures

+ 1 - 1
django/contrib/gis/db/backends/postgis/features.py

@@ -1,5 +1,5 @@
 from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
 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
     DatabaseFeatures as Psycopg2DatabaseFeatures
 
 
 
 

+ 1 - 2
django/contrib/gis/db/backends/postgis/introspection.py

@@ -1,6 +1,5 @@
 from django.contrib.gis.gdal import OGRGeomType
 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):
 class GeoIntrospectionError(Exception):

+ 1 - 2
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.geometry.backend import Geometry
 from django.contrib.gis.measure import Distance
 from django.contrib.gis.measure import Distance
 from django.core.exceptions import ImproperlyConfigured
 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.db.utils import ProgrammingError
 from django.utils.functional import cached_property
 from django.utils.functional import cached_property
 
 

+ 1 - 1
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):
 class PostGISSchemaEditor(DatabaseSchemaEditor):

+ 0 - 0
django/db/backends/postgresql_psycopg2/__init__.py → django/db/backends/postgresql/__init__.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/base.py → django/db/backends/postgresql/base.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/client.py → django/db/backends/postgresql/client.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/creation.py → django/db/backends/postgresql/creation.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/features.py → django/db/backends/postgresql/features.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/introspection.py → django/db/backends/postgresql/introspection.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/operations.py → django/db/backends/postgresql/operations.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/schema.py → django/db/backends/postgresql/schema.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/utils.py → django/db/backends/postgresql/utils.py


+ 0 - 0
django/db/backends/postgresql_psycopg2/version.py → django/db/backends/postgresql/version.py


+ 10 - 2
django/db/utils.py

@@ -104,7 +104,14 @@ class DatabaseErrorWrapper(object):
 
 
 
 
 def load_backend(backend_name):
 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:
     try:
         return import_module('%s.base' % backend_name)
         return import_module('%s.base' % backend_name)
     except ImportError as e_user:
     except ImportError as e_user:
@@ -114,7 +121,8 @@ def load_backend(backend_name):
         try:
         try:
             builtin_backends = [
             builtin_backends = [
                 name for _, name, ispkg in pkgutil.iter_modules([npath(backend_dir)])
                 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:
         except EnvironmentError:
             builtin_backends = []
             builtin_backends = []
         if backend_name not in ['django.db.backends.%s' % b for b in
         if backend_name not in ['django.db.backends.%s' % b for b in

+ 1 - 1
docs/intro/tutorial02.txt

@@ -26,7 +26,7 @@ settings:
 
 
 * :setting:`ENGINE <DATABASE-ENGINE>` -- Either
 * :setting:`ENGINE <DATABASE-ENGINE>` -- Either
   ``'django.db.backends.sqlite3'``,
   ``'django.db.backends.sqlite3'``,
-  ``'django.db.backends.postgresql_psycopg2'``,
+  ``'django.db.backends.postgresql'``,
   ``'django.db.backends.mysql'``, or
   ``'django.db.backends.mysql'``, or
   ``'django.db.backends.oracle'``. Other backends are :ref:`also available
   ``'django.db.backends.oracle'``. Other backends are :ref:`also available
   <third-party-notes>`.
   <third-party-notes>`.

+ 1 - 1
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
 another transaction, :exc:`~django.db.DatabaseError` will be raised when the
 queryset is evaluated.
 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
 backends support ``select_for_update()``. However, MySQL has no support for the
 ``nowait`` argument. Obviously, users of external third-party backends should
 ``nowait`` argument. Obviously, users of external third-party backends should
 check with their backend's documentation for specifics in those cases.
 check with their backend's documentation for specifics in those cases.

+ 10 - 6
docs/ref/settings.txt

@@ -459,7 +459,7 @@ other database types. This example is for PostgreSQL::
 
 
     DATABASES = {
     DATABASES = {
         'default': {
         'default': {
-            'ENGINE': 'django.db.backends.postgresql_psycopg2',
+            'ENGINE': 'django.db.backends.postgresql',
             'NAME': 'mydatabase',
             'NAME': 'mydatabase',
             'USER': 'mydatabaseuser',
             'USER': 'mydatabaseuser',
             'PASSWORD': 'mypassword',
             'PASSWORD': 'mypassword',
@@ -500,14 +500,19 @@ Default: ``''`` (Empty string)
 
 
 The database backend to use. The built-in database backends are:
 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.mysql'``
 * ``'django.db.backends.sqlite3'``
 * ``'django.db.backends.sqlite3'``
 * ``'django.db.backends.oracle'``
 * ``'django.db.backends.oracle'``
 
 
 You can use a database backend that doesn't ship with Django by setting
 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
 .. 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
 string is passed directly through to the database, so its format is
 backend-specific.
 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
 .. _PostgreSQL: http://www.postgresql.org/docs/current/static/multibyte.html
 .. _MySQL: http://dev.mysql.com/doc/refman/5.6/en/charset-database.html
 .. _MySQL: http://dev.mysql.com/doc/refman/5.6/en/charset-database.html

+ 1 - 1
docs/ref/signals.txt

@@ -625,7 +625,7 @@ Arguments sent with this signal:
 
 
 ``sender``
 ``sender``
     The database wrapper class -- i.e.
     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.
     ``django.db.backends.mysql.DatabaseWrapper``, etc.
 
 
 ``connection``
 ``connection``

+ 7 - 0
docs/releases/1.9.txt

@@ -578,6 +578,13 @@ Validators
 * Added :func:`~django.core.validators.validate_unicode_slug` to validate slugs
 * Added :func:`~django.core.validators.validate_unicode_slug` to validate slugs
   that may contain Unicode characters.
   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
 Backwards incompatible changes in 1.9
 =====================================
 =====================================
 
 

+ 1 - 1
docs/topics/db/multi-db.txt

@@ -29,7 +29,7 @@ databases -- a default PostgreSQL database and a MySQL database called
     DATABASES = {
     DATABASES = {
         'default': {
         'default': {
             'NAME': 'app_data',
             'NAME': 'app_data',
-            'ENGINE': 'django.db.backends.postgresql_psycopg2',
+            'ENGINE': 'django.db.backends.postgresql',
             'USER': 'postgres_user',
             'USER': 'postgres_user',
             'PASSWORD': 's3krit'
             'PASSWORD': 's3krit'
         },
         },

+ 1 - 1
tests/backends/test_utils.py

@@ -9,7 +9,7 @@ class TestLoadBackend(SimpleTestCase):
         msg = (
         msg = (
             "'foo' isn't an available database backend.\n"
             "'foo' isn't an available database backend.\n"
             "Try using 'django.db.backends.XXX', where XXX is one of:\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"
             "Error was: No module named %s"
         ) % "foo.base" if six.PY2 else "'foo'"
         ) % "foo.base" if six.PY2 else "'foo'"
         with self.assertRaisesMessage(ImproperlyConfigured, msg):
         with self.assertRaisesMessage(ImproperlyConfigured, msg):

+ 4 - 4
tests/backends/tests.py

@@ -18,7 +18,7 @@ from django.db import (
     reset_queries, transaction,
     reset_queries, transaction,
 )
 )
 from django.db.backends.base.base import BaseDatabaseWrapper
 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.signals import connection_created
 from django.db.backends.utils import CursorWrapper, format_number
 from django.db.backends.utils import CursorWrapper, format_number
 from django.db.models import Avg, StdDev, Sum, Variance
 from django.db.models import Avg, StdDev, Sum, Variance
@@ -313,7 +313,7 @@ class PostgreSQLTests(TestCase):
         self.assertEqual(a[0], b[0])
         self.assertEqual(a[0], b[0])
 
 
     def test_lookup_cast(self):
     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)
         do = DatabaseOperations(connection=None)
         for lookup in ('iexact', 'contains', 'icontains', 'startswith',
         for lookup in ('iexact', 'contains', 'icontains', 'startswith',
@@ -321,8 +321,8 @@ class PostgreSQLTests(TestCase):
             self.assertIn('::text', do.lookup_cast(lookup))
             self.assertIn('::text', do.lookup_cast(lookup))
 
 
     def test_correct_extraction_psycopg2_version(self):
     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'):
         with mock.patch(version_path, '2.6.9'):
             self.assertEqual(psycopg2_version(), (2, 6, 9))
             self.assertEqual(psycopg2_version(), (2, 6, 9))

+ 1 - 1
tests/dbshell/test_postgresql_psycopg2.py

@@ -4,7 +4,7 @@ from __future__ import unicode_literals
 import locale
 import locale
 import os
 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.test import SimpleTestCase, mock
 from django.utils import six
 from django.utils import six
 from django.utils.encoding import force_bytes, force_str
 from django.utils.encoding import force_bytes, force_str