2013-02-10 23:15:49 +08:00
|
|
|
import datetime
|
2013-02-18 18:37:26 +08:00
|
|
|
import time
|
2013-02-10 23:15:49 +08:00
|
|
|
|
2011-12-16 21:40:19 +08:00
|
|
|
from django.db.utils import DatabaseError
|
|
|
|
|
2011-02-12 21:02:42 +08:00
|
|
|
try:
|
2012-08-18 16:56:56 +08:00
|
|
|
from django.utils.six.moves import _thread as thread
|
2011-02-12 21:02:42 +08:00
|
|
|
except ImportError:
|
2012-07-20 22:16:57 +08:00
|
|
|
from django.utils.six.moves import _dummy_thread as thread
|
2013-01-13 04:10:08 +08:00
|
|
|
from collections import namedtuple
|
2011-08-07 08:43:26 +08:00
|
|
|
from contextlib import contextmanager
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2011-01-12 21:39:31 +08:00
|
|
|
from django.conf import settings
|
2009-12-22 23:18:51 +08:00
|
|
|
from django.db import DEFAULT_DB_ALIAS
|
2013-02-19 00:12:42 +08:00
|
|
|
from django.db.backends.signals import connection_created
|
2008-07-29 13:09:29 +08:00
|
|
|
from django.db.backends import util
|
2011-02-12 21:02:42 +08:00
|
|
|
from django.db.transaction import TransactionManagementError
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
from django.db.utils import DatabaseErrorWrapper
|
2012-06-09 21:59:52 +08:00
|
|
|
from django.utils.functional import cached_property
|
2009-12-22 23:18:51 +08:00
|
|
|
from django.utils.importlib import import_module
|
2012-07-20 20:48:51 +08:00
|
|
|
from django.utils import six
|
2013-02-10 23:15:49 +08:00
|
|
|
from django.utils import timezone
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2011-01-12 21:39:31 +08:00
|
|
|
|
2011-12-16 21:40:19 +08:00
|
|
|
class BaseDatabaseWrapper(object):
|
2007-08-20 06:29:57 +08:00
|
|
|
"""
|
|
|
|
Represents a database connection.
|
|
|
|
"""
|
|
|
|
ops = None
|
2010-12-04 02:15:54 +08:00
|
|
|
vendor = 'unknown'
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2011-12-16 21:40:19 +08:00
|
|
|
def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS,
|
|
|
|
allow_thread_sharing=False):
|
2009-03-11 11:39:34 +08:00
|
|
|
# `settings_dict` should be a dictionary containing keys such as
|
2009-12-22 23:18:51 +08:00
|
|
|
# NAME, USER, etc. It's called `settings_dict` instead of `settings`
|
|
|
|
# to disambiguate it from Django settings modules.
|
2007-08-20 05:30:57 +08:00
|
|
|
self.connection = None
|
|
|
|
self.queries = []
|
2009-03-11 11:39:34 +08:00
|
|
|
self.settings_dict = settings_dict
|
2009-12-22 23:18:51 +08:00
|
|
|
self.alias = alias
|
2010-10-12 11:33:19 +08:00
|
|
|
self.use_debug_cursor = None
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
# Savepoint management related attributes
|
2011-01-17 17:52:47 +08:00
|
|
|
self.savepoint_state = 0
|
2013-03-02 19:12:51 +08:00
|
|
|
|
|
|
|
# Transaction management related attributes
|
2013-03-02 20:47:46 +08:00
|
|
|
self.autocommit = False
|
2013-03-02 19:12:51 +08:00
|
|
|
self.transaction_state = []
|
2013-02-20 09:11:54 +08:00
|
|
|
# Tracks if the connection is believed to be in transaction. This is
|
|
|
|
# set somewhat aggressively, as the DBAPI doesn't make it easy to
|
|
|
|
# deduce if the connection is in transaction or not.
|
|
|
|
self._dirty = False
|
2013-03-13 21:08:32 +08:00
|
|
|
# Tracks if the connection is in a transaction managed by 'atomic'.
|
2013-03-05 05:17:35 +08:00
|
|
|
self.in_atomic_block = False
|
2013-03-13 21:54:44 +08:00
|
|
|
# List of savepoints created by 'atomic'
|
|
|
|
self.savepoint_ids = []
|
2013-03-13 21:08:32 +08:00
|
|
|
# Tracks if the outermost 'atomic' block should commit on exit,
|
|
|
|
# ie. if autocommit was active on entry.
|
|
|
|
self.commit_on_exit = True
|
2013-03-08 22:44:41 +08:00
|
|
|
# Tracks if the transaction should be rolled back to the next
|
|
|
|
# available savepoint because of an exception in an inner block.
|
|
|
|
self.needs_rollback = False
|
2011-01-17 17:52:47 +08:00
|
|
|
|
2013-02-18 18:37:26 +08:00
|
|
|
# Connection termination related attributes
|
|
|
|
self.close_at = None
|
|
|
|
self.errors_occurred = False
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
# Thread-safety related attributes
|
|
|
|
self.allow_thread_sharing = allow_thread_sharing
|
|
|
|
self._thread_ident = thread.get_ident()
|
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def __eq__(self, other):
|
2010-11-19 16:08:08 +08:00
|
|
|
return self.alias == other.alias
|
2009-12-22 23:18:51 +08:00
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
return not self == other
|
2007-08-20 05:30:57 +08:00
|
|
|
|
2013-02-26 05:53:08 +08:00
|
|
|
def __hash__(self):
|
|
|
|
return hash(self.alias)
|
2012-08-18 17:02:38 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Backend-specific methods for creating connections and cursors #####
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
|
2013-02-19 02:31:10 +08:00
|
|
|
def get_connection_params(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""Returns a dict of parameters suitable for get_new_connection."""
|
2013-02-19 02:31:10 +08:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def get_new_connection(self, conn_params):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""Opens a connection to the database."""
|
2013-02-19 02:31:10 +08:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def init_connection_state(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""Initializes the database connection settings."""
|
2013-02-19 02:31:10 +08:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def create_cursor(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""Creates a cursor. Assumes that a connection is established."""
|
2013-02-19 02:31:10 +08:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2013-03-03 22:43:24 +08:00
|
|
|
##### Backend-specific methods for creating connections #####
|
|
|
|
|
|
|
|
def connect(self):
|
|
|
|
"""Connects to the database. Assumes that the connection is closed."""
|
2013-03-13 21:54:44 +08:00
|
|
|
# In case the previous connection was closed while in an atomic block
|
|
|
|
self.in_atomic_block = False
|
|
|
|
self.savepoint_ids = []
|
2013-03-03 22:43:24 +08:00
|
|
|
# Reset parameters defining when to close the connection
|
|
|
|
max_age = self.settings_dict['CONN_MAX_AGE']
|
|
|
|
self.close_at = None if max_age is None else time.time() + max_age
|
|
|
|
self.errors_occurred = False
|
|
|
|
# Establish the connection
|
|
|
|
conn_params = self.get_connection_params()
|
|
|
|
self.connection = self.get_new_connection(conn_params)
|
|
|
|
self.init_connection_state()
|
2013-03-06 18:12:24 +08:00
|
|
|
if self.settings_dict['AUTOCOMMIT']:
|
2013-03-11 22:10:58 +08:00
|
|
|
self.set_autocommit(True)
|
2013-03-03 22:43:24 +08:00
|
|
|
connection_created.send(sender=self.__class__, connection=self)
|
|
|
|
|
|
|
|
def ensure_connection(self):
|
|
|
|
"""
|
|
|
|
Guarantees that a connection to the database is established.
|
|
|
|
"""
|
|
|
|
if self.connection is None:
|
|
|
|
with self.wrap_database_errors():
|
|
|
|
self.connect()
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Backend-specific wrappers for PEP-249 connection methods #####
|
|
|
|
|
2013-02-19 00:12:42 +08:00
|
|
|
def _cursor(self):
|
2013-03-03 22:43:24 +08:00
|
|
|
self.ensure_connection()
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
with self.wrap_database_errors():
|
|
|
|
return self.create_cursor()
|
2013-02-19 00:12:42 +08:00
|
|
|
|
2007-08-20 05:30:57 +08:00
|
|
|
def _commit(self):
|
|
|
|
if self.connection is not None:
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
with self.wrap_database_errors():
|
|
|
|
return self.connection.commit()
|
2007-08-20 05:30:57 +08:00
|
|
|
|
|
|
|
def _rollback(self):
|
|
|
|
if self.connection is not None:
|
Refactored database exceptions wrapping.
Squashed commit of the following:
commit 2181d833ed1a2e422494738dcef311164c4e097e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed Feb 27 14:28:39 2013 +0100
Fixed #15901 -- Wrapped all PEP-249 exceptions.
commit 5476a5d93c19aa2f928c497d39ce6e33f52694e2
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:26:52 2013 +0100
Added PEP 3134 exception chaining.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 9365fad0a650328002fb424457d675a273c95802
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 17:13:49 2013 +0100
Improved API for wrapping database errors.
Thanks Alex Gaynor for the proposal.
commit 1b463b765f2826f73a8d9266795cd5da4f8d5e9e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 15:00:39 2013 +0100
Removed redundant exception wrapping.
This is now taken care of by the cursor wrapper.
commit 524bc7345a724bf526bdd2dd1bcf5ede67d6bb5c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:55:10 2013 +0100
Wrapped database exceptions in the base backend.
This covers the most common PEP-249 APIs:
- Connection APIs: close(), commit(), rollback(), cursor()
- Cursor APIs: callproc(), close(), execute(), executemany(),
fetchone(), fetchmany(), fetchall(), nextset().
Fixed #19920.
commit a66746bb5f0839f35543222787fce3b6a0d0a3ea
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Feb 26 14:53:34 2013 +0100
Added a wrap_database_exception context manager and decorator.
It re-throws backend-specific exceptions using Django's common wrappers.
2013-02-26 21:53:34 +08:00
|
|
|
with self.wrap_database_errors():
|
|
|
|
return self.connection.rollback()
|
|
|
|
|
|
|
|
def _close(self):
|
|
|
|
if self.connection is not None:
|
|
|
|
with self.wrap_database_errors():
|
|
|
|
return self.connection.close()
|
2007-08-20 05:30:57 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Generic wrappers for PEP-249 connection methods #####
|
|
|
|
|
|
|
|
def cursor(self):
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Creates a cursor, opening a connection if necessary.
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
self.validate_thread_sharing()
|
|
|
|
if (self.use_debug_cursor or
|
|
|
|
(self.use_debug_cursor is None and settings.DEBUG)):
|
|
|
|
cursor = self.make_debug_cursor(self._cursor())
|
|
|
|
else:
|
|
|
|
cursor = util.CursorWrapper(self._cursor(), self)
|
|
|
|
return cursor
|
2009-03-11 15:06:50 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
def commit(self):
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
2013-03-05 05:17:35 +08:00
|
|
|
Commits a transaction and resets the dirty flag.
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
self.validate_thread_sharing()
|
2013-03-05 06:26:31 +08:00
|
|
|
self.validate_no_atomic_block()
|
2013-03-02 19:12:51 +08:00
|
|
|
self._commit()
|
|
|
|
self.set_clean()
|
|
|
|
|
|
|
|
def rollback(self):
|
|
|
|
"""
|
2013-03-05 05:17:35 +08:00
|
|
|
Rolls back a transaction and resets the dirty flag.
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
|
|
|
self.validate_thread_sharing()
|
2013-03-05 06:26:31 +08:00
|
|
|
self.validate_no_atomic_block()
|
2013-03-02 19:12:51 +08:00
|
|
|
self._rollback()
|
|
|
|
self.set_clean()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
"""
|
|
|
|
Closes the connection to the database.
|
|
|
|
"""
|
|
|
|
self.validate_thread_sharing()
|
2013-03-13 21:54:44 +08:00
|
|
|
# Don't call validate_no_atomic_block() to avoid making it difficult
|
|
|
|
# to get rid of a connection in an invalid state. The next connect()
|
|
|
|
# will reset the transaction state anyway.
|
2013-03-02 19:12:51 +08:00
|
|
|
try:
|
|
|
|
self._close()
|
|
|
|
finally:
|
|
|
|
self.connection = None
|
|
|
|
self.set_clean()
|
|
|
|
|
|
|
|
##### Backend-specific savepoint management methods #####
|
2009-03-11 15:06:50 +08:00
|
|
|
|
2008-08-12 13:34:56 +08:00
|
|
|
def _savepoint(self, sid):
|
2009-04-11 15:51:07 +08:00
|
|
|
self.cursor().execute(self.ops.savepoint_create_sql(sid))
|
2008-08-12 13:34:56 +08:00
|
|
|
|
|
|
|
def _savepoint_rollback(self, sid):
|
2009-04-11 15:51:07 +08:00
|
|
|
self.cursor().execute(self.ops.savepoint_rollback_sql(sid))
|
2008-08-12 13:34:56 +08:00
|
|
|
|
|
|
|
def _savepoint_commit(self, sid):
|
2009-04-11 15:51:07 +08:00
|
|
|
self.cursor().execute(self.ops.savepoint_commit_sql(sid))
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2013-03-01 17:09:22 +08:00
|
|
|
def _savepoint_allowed(self):
|
|
|
|
# Savepoints cannot be created outside a transaction
|
|
|
|
return self.features.uses_savepoints and not self.autocommit
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Generic savepoint management methods #####
|
|
|
|
|
|
|
|
def savepoint(self):
|
2013-02-06 05:52:29 +08:00
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
Creates a savepoint inside the current transaction. Returns an
|
|
|
|
identifier for the savepoint that will be used for the subsequent
|
|
|
|
rollback or commit. Does nothing if savepoints are not supported.
|
2013-02-06 05:52:29 +08:00
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
if not self._savepoint_allowed():
|
|
|
|
return
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
thread_ident = thread.get_ident()
|
2013-03-01 17:09:22 +08:00
|
|
|
tid = str(thread_ident).replace('-', '')
|
2013-03-02 19:12:51 +08:00
|
|
|
|
|
|
|
self.savepoint_state += 1
|
|
|
|
sid = "s%s_x%d" % (tid, self.savepoint_state)
|
2013-03-01 17:09:22 +08:00
|
|
|
|
|
|
|
self.validate_thread_sharing()
|
2013-03-02 19:12:51 +08:00
|
|
|
self._savepoint(sid)
|
2013-03-01 17:09:22 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
return sid
|
|
|
|
|
|
|
|
def savepoint_rollback(self, sid):
|
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
Rolls back to a savepoint. Does nothing if savepoints are not supported.
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
if not self._savepoint_allowed():
|
|
|
|
return
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
self.validate_thread_sharing()
|
2013-03-01 17:09:22 +08:00
|
|
|
self._savepoint_rollback(sid)
|
2013-03-02 19:12:51 +08:00
|
|
|
|
|
|
|
def savepoint_commit(self, sid):
|
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
Releases a savepoint. Does nothing if savepoints are not supported.
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
2013-03-01 17:09:22 +08:00
|
|
|
if not self._savepoint_allowed():
|
|
|
|
return
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
self.validate_thread_sharing()
|
2013-03-01 17:09:22 +08:00
|
|
|
self._savepoint_commit(sid)
|
2013-03-02 19:12:51 +08:00
|
|
|
|
|
|
|
def clean_savepoints(self):
|
|
|
|
"""
|
|
|
|
Resets the counter used to generate unique savepoint ids in this thread.
|
|
|
|
"""
|
|
|
|
self.savepoint_state = 0
|
|
|
|
|
|
|
|
##### Backend-specific transaction management methods #####
|
|
|
|
|
2013-03-02 20:47:46 +08:00
|
|
|
def _set_autocommit(self, autocommit):
|
|
|
|
"""
|
|
|
|
Backend-specific implementation to enable or disable autocommit.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Generic transaction management methods #####
|
2013-02-06 05:52:29 +08:00
|
|
|
|
2013-03-03 03:25:25 +08:00
|
|
|
def enter_transaction_management(self, managed=True, forced=False):
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
|
|
|
Enters transaction management for a running thread. It must be balanced with
|
|
|
|
the appropriate leave_transaction_management call, since the actual state is
|
|
|
|
managed as a stack.
|
|
|
|
|
|
|
|
The state and dirty flag are carried over from the surrounding block or
|
|
|
|
from the settings, if there is no surrounding block (dirty is always false
|
|
|
|
when no current block is running).
|
2013-03-03 03:25:25 +08:00
|
|
|
|
|
|
|
If you switch off transaction management and there is a pending
|
|
|
|
commit/rollback, the data will be commited, unless "forced" is True.
|
2011-02-12 21:02:42 +08:00
|
|
|
"""
|
2013-03-05 06:26:31 +08:00
|
|
|
self.validate_no_atomic_block()
|
|
|
|
|
2013-03-06 05:30:55 +08:00
|
|
|
self.ensure_connection()
|
|
|
|
|
2013-03-03 03:25:25 +08:00
|
|
|
self.transaction_state.append(managed)
|
2013-03-03 22:48:52 +08:00
|
|
|
|
2013-03-03 03:25:25 +08:00
|
|
|
if not managed and self.is_dirty() and not forced:
|
|
|
|
self.commit()
|
2013-03-04 22:24:01 +08:00
|
|
|
self.set_clean()
|
|
|
|
|
|
|
|
if managed == self.autocommit:
|
|
|
|
self.set_autocommit(not managed)
|
2011-02-12 21:02:42 +08:00
|
|
|
|
|
|
|
def leave_transaction_management(self):
|
|
|
|
"""
|
|
|
|
Leaves transaction management for a running thread. A dirty flag is carried
|
|
|
|
over to the surrounding block, as a commit will commit all changes, even
|
|
|
|
those from outside. (Commits are on connection level.)
|
|
|
|
"""
|
2013-03-05 06:26:31 +08:00
|
|
|
self.validate_no_atomic_block()
|
|
|
|
|
2013-03-06 05:30:55 +08:00
|
|
|
self.ensure_connection()
|
|
|
|
|
2011-02-12 21:02:42 +08:00
|
|
|
if self.transaction_state:
|
|
|
|
del self.transaction_state[-1]
|
|
|
|
else:
|
2012-05-27 04:19:13 +08:00
|
|
|
raise TransactionManagementError(
|
|
|
|
"This code isn't under transaction management")
|
2013-03-03 22:48:52 +08:00
|
|
|
|
2013-03-04 22:24:01 +08:00
|
|
|
if self.transaction_state:
|
|
|
|
managed = self.transaction_state[-1]
|
|
|
|
else:
|
2013-03-06 18:12:24 +08:00
|
|
|
managed = not self.settings_dict['AUTOCOMMIT']
|
2013-03-03 22:48:52 +08:00
|
|
|
|
|
|
|
if self._dirty:
|
2011-02-12 21:02:42 +08:00
|
|
|
self.rollback()
|
2013-03-04 22:24:01 +08:00
|
|
|
if managed == self.autocommit:
|
|
|
|
self.set_autocommit(not managed)
|
2012-05-27 04:19:13 +08:00
|
|
|
raise TransactionManagementError(
|
|
|
|
"Transaction managed block ended with pending COMMIT/ROLLBACK")
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2013-03-04 22:24:01 +08:00
|
|
|
if managed == self.autocommit:
|
|
|
|
self.set_autocommit(not managed)
|
2013-03-03 22:48:52 +08:00
|
|
|
|
2013-03-11 22:10:58 +08:00
|
|
|
def set_autocommit(self, autocommit):
|
2013-03-02 20:47:46 +08:00
|
|
|
"""
|
|
|
|
Enable or disable autocommit.
|
|
|
|
"""
|
2013-03-05 06:26:31 +08:00
|
|
|
self.validate_no_atomic_block()
|
2013-03-03 22:43:24 +08:00
|
|
|
self.ensure_connection()
|
2013-03-02 20:47:46 +08:00
|
|
|
self._set_autocommit(autocommit)
|
|
|
|
self.autocommit = autocommit
|
|
|
|
|
2013-03-05 06:26:31 +08:00
|
|
|
def validate_no_atomic_block(self):
|
|
|
|
"""
|
|
|
|
Raise an error if an atomic block is active.
|
|
|
|
"""
|
|
|
|
if self.in_atomic_block:
|
|
|
|
raise TransactionManagementError(
|
|
|
|
"This is forbidden when an 'atomic' block is active.")
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
def abort(self):
|
2011-12-16 21:40:19 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Roll back any ongoing transaction and clean the transaction state
|
|
|
|
stack.
|
2011-12-16 21:40:19 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
if self._dirty:
|
|
|
|
self.rollback()
|
|
|
|
while self.transaction_state:
|
|
|
|
self.leave_transaction_management()
|
2011-12-16 21:40:19 +08:00
|
|
|
|
2011-02-12 21:02:42 +08:00
|
|
|
def is_dirty(self):
|
|
|
|
"""
|
|
|
|
Returns True if the current transaction requires a commit for changes to
|
|
|
|
happen.
|
|
|
|
"""
|
|
|
|
return self._dirty
|
|
|
|
|
|
|
|
def set_dirty(self):
|
|
|
|
"""
|
|
|
|
Sets a dirty flag for the current thread and code streak. This can be used
|
|
|
|
to decide in a managed block of code to decide whether there are open
|
|
|
|
changes waiting for commit.
|
|
|
|
"""
|
2013-03-07 18:50:49 +08:00
|
|
|
if not self.autocommit:
|
|
|
|
self._dirty = True
|
2011-02-12 21:02:42 +08:00
|
|
|
|
|
|
|
def set_clean(self):
|
|
|
|
"""
|
|
|
|
Resets a dirty flag for the current thread and code streak. This can be used
|
|
|
|
to decide in a managed block of code to decide whether a commit or rollback
|
|
|
|
should happen.
|
|
|
|
"""
|
2013-02-20 09:11:54 +08:00
|
|
|
self._dirty = False
|
2011-02-12 21:02:42 +08:00
|
|
|
self.clean_savepoints()
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Foreign key constraints checks handling #####
|
2011-02-12 21:02:42 +08:00
|
|
|
|
2011-08-07 08:43:26 +08:00
|
|
|
@contextmanager
|
|
|
|
def constraint_checks_disabled(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
|
|
|
Context manager that disables foreign key constraint checking.
|
|
|
|
"""
|
2011-08-07 08:43:26 +08:00
|
|
|
disabled = self.disable_constraint_checking()
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
if disabled:
|
|
|
|
self.enable_constraint_checking()
|
|
|
|
|
|
|
|
def disable_constraint_checking(self):
|
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Backends can implement as needed to temporarily disable foreign key
|
|
|
|
constraint checking.
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def enable_constraint_checking(self):
|
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Backends can implement as needed to re-enable foreign key constraint
|
|
|
|
checking.
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def check_constraints(self, table_names=None):
|
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Backends can override this method if they can apply constraint
|
|
|
|
checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE"). Should raise an
|
|
|
|
IntegrityError if any invalid foreign key references are encountered.
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Connection termination handling #####
|
|
|
|
|
|
|
|
def is_usable(self):
|
|
|
|
"""
|
|
|
|
Tests if the database connection is usable.
|
|
|
|
This function may assume that self.connection is not None.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
2007-08-20 05:30:57 +08:00
|
|
|
|
2013-02-18 18:37:26 +08:00
|
|
|
def close_if_unusable_or_obsolete(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
|
|
|
Closes the current connection if unrecoverable errors have occurred,
|
|
|
|
or if it outlived its maximum age.
|
|
|
|
"""
|
2013-02-18 18:37:26 +08:00
|
|
|
if self.connection is not None:
|
2013-03-07 21:47:50 +08:00
|
|
|
# If the application didn't restore the original autocommit setting,
|
|
|
|
# don't take chances, drop the connection.
|
|
|
|
if self.autocommit != self.settings_dict['AUTOCOMMIT']:
|
|
|
|
self.close()
|
|
|
|
return
|
|
|
|
|
2013-02-18 18:37:26 +08:00
|
|
|
if self.errors_occurred:
|
|
|
|
if self.is_usable():
|
|
|
|
self.errors_occurred = False
|
|
|
|
else:
|
|
|
|
self.close()
|
|
|
|
return
|
2013-03-07 21:47:50 +08:00
|
|
|
|
2013-02-18 18:37:26 +08:00
|
|
|
if self.close_at is not None and time.time() >= self.close_at:
|
|
|
|
self.close()
|
|
|
|
return
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Thread safety handling #####
|
2013-02-18 18:37:26 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
def validate_thread_sharing(self):
|
2013-02-18 18:37:26 +08:00
|
|
|
"""
|
2013-03-02 19:12:51 +08:00
|
|
|
Validates that the connection isn't accessed by another thread than the
|
|
|
|
one which originally created it, unless the connection was explicitly
|
|
|
|
authorized to be shared between threads (via the `allow_thread_sharing`
|
|
|
|
property). Raises an exception if the validation fails.
|
|
|
|
"""
|
|
|
|
if not (self.allow_thread_sharing
|
|
|
|
or self._thread_ident == thread.get_ident()):
|
|
|
|
raise DatabaseError("DatabaseWrapper objects created in a "
|
|
|
|
"thread can only be used in that same thread. The object "
|
|
|
|
"with alias '%s' was created in thread id %s and this is "
|
|
|
|
"thread id %s."
|
|
|
|
% (self.alias, self._thread_ident, thread.get_ident()))
|
2013-02-18 18:37:26 +08:00
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
##### Miscellaneous #####
|
|
|
|
|
|
|
|
def wrap_database_errors(self):
|
|
|
|
"""
|
|
|
|
Context manager and decorator that re-throws backend-specific database
|
|
|
|
exceptions using Django's common wrappers.
|
|
|
|
"""
|
|
|
|
return DatabaseErrorWrapper(self)
|
2007-08-20 05:30:57 +08:00
|
|
|
|
|
|
|
def make_debug_cursor(self, cursor):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
|
|
|
Creates a cursor that logs all queries in self.queries.
|
|
|
|
"""
|
2007-08-20 05:30:57 +08:00
|
|
|
return util.CursorDebugWrapper(cursor, self)
|
2007-08-20 06:29:57 +08:00
|
|
|
|
2013-02-19 17:51:24 +08:00
|
|
|
@contextmanager
|
|
|
|
def temporary_connection(self):
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
|
|
|
Context manager that ensures that a connection is established, and
|
|
|
|
if it opened one, closes it to avoid leaving a dangling connection.
|
|
|
|
This is useful for operations outside of the request-response cycle.
|
2013-03-12 04:08:49 +08:00
|
|
|
|
|
|
|
Provides a cursor: with self.temporary_connection() as cursor: ...
|
2013-03-02 19:12:51 +08:00
|
|
|
"""
|
2013-02-19 17:51:24 +08:00
|
|
|
must_close = self.connection is None
|
|
|
|
cursor = self.cursor()
|
|
|
|
try:
|
2013-03-12 04:08:49 +08:00
|
|
|
yield cursor
|
2013-02-19 17:51:24 +08:00
|
|
|
finally:
|
|
|
|
cursor.close()
|
|
|
|
if must_close:
|
|
|
|
self.close()
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
|
2013-03-05 05:17:35 +08:00
|
|
|
def _start_transaction_under_autocommit(self):
|
|
|
|
"""
|
|
|
|
Only required when autocommits_when_autocommit_is_off = True.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2013-03-02 19:12:51 +08:00
|
|
|
|
2007-08-20 10:20:33 +08:00
|
|
|
class BaseDatabaseFeatures(object):
|
2009-01-15 19:06:34 +08:00
|
|
|
allows_group_by_pk = False
|
2008-07-29 13:09:29 +08:00
|
|
|
# True if django.db.backend.utils.typecast_timestamp is used on values
|
|
|
|
# returned from dates() calls.
|
2007-08-20 10:20:33 +08:00
|
|
|
needs_datetime_string_cast = True
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
empty_fetchmany_value = []
|
2008-04-28 19:51:52 +08:00
|
|
|
update_can_self_select = True
|
2010-10-11 20:55:17 +08:00
|
|
|
|
|
|
|
# Does the backend distinguish between '' and None?
|
2008-06-16 11:15:04 +08:00
|
|
|
interprets_empty_strings_as_nulls = False
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2011-03-09 06:41:25 +08:00
|
|
|
# Does the backend allow inserting duplicate rows when a unique_together
|
|
|
|
# constraint exists, but one of the unique_together columns is NULL?
|
|
|
|
ignores_nulls_in_unique_constraints = True
|
|
|
|
|
2008-07-16 02:47:32 +08:00
|
|
|
can_use_chunked_reads = True
|
2009-03-11 15:06:50 +08:00
|
|
|
can_return_id_from_insert = False
|
2011-09-10 03:22:28 +08:00
|
|
|
has_bulk_insert = False
|
2008-08-12 13:34:56 +08:00
|
|
|
uses_savepoints = False
|
2011-09-10 03:22:28 +08:00
|
|
|
can_combine_inserts_with_and_without_auto_increment_pk = False
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2008-09-01 08:49:03 +08:00
|
|
|
# If True, don't use integer foreign keys referring to, e.g., positive
|
|
|
|
# integer primary keys.
|
|
|
|
related_fields_match_type = False
|
2010-04-05 01:05:43 +08:00
|
|
|
allow_sliced_subqueries = True
|
2011-04-21 04:42:07 +08:00
|
|
|
has_select_for_update = False
|
|
|
|
has_select_for_update_nowait = False
|
2007-08-20 10:20:33 +08:00
|
|
|
|
2011-12-06 07:11:43 +08:00
|
|
|
supports_select_related = True
|
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
# Does the default test database allow multiple connections?
|
|
|
|
# Usually an indication that the test database is in-memory
|
|
|
|
test_db_allows_multiple_connections = True
|
|
|
|
|
|
|
|
# Can an object be saved without an explicit primary key?
|
|
|
|
supports_unspecified_pk = False
|
|
|
|
|
|
|
|
# Can a fixture contain forward references? i.e., are
|
|
|
|
# FK constraints checked at the end of transaction, or
|
|
|
|
# at the end of each save operation?
|
|
|
|
supports_forward_references = True
|
|
|
|
|
|
|
|
# Does a dirty transaction need to be rolled back
|
|
|
|
# before the cursor can be used again?
|
|
|
|
requires_rollback_on_dirty_transaction = False
|
|
|
|
|
|
|
|
# Does the backend allow very long model names without error?
|
|
|
|
supports_long_model_names = True
|
|
|
|
|
|
|
|
# Is there a REAL datatype in addition to floats/doubles?
|
|
|
|
has_real_datatype = False
|
|
|
|
supports_subqueries_in_group_by = True
|
|
|
|
supports_bitwise_or = True
|
|
|
|
|
|
|
|
# Do time/datetime fields have microsecond precision?
|
|
|
|
supports_microsecond_precision = True
|
|
|
|
|
|
|
|
# Does the __regex lookup support backreferencing and grouping?
|
|
|
|
supports_regex_backreferencing = True
|
|
|
|
|
|
|
|
# Can date/datetime lookups be performed using a string?
|
|
|
|
supports_date_lookup_using_string = True
|
|
|
|
|
|
|
|
# Can datetimes with timezones be used?
|
|
|
|
supports_timezones = True
|
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
# Does the database have a copy of the zoneinfo database?
|
|
|
|
has_zoneinfo_database = True
|
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
# When performing a GROUP BY, is an ORDER BY NULL required
|
|
|
|
# to remove any ordering?
|
|
|
|
requires_explicit_null_ordering_when_grouping = False
|
|
|
|
|
|
|
|
# Is there a 1000 item limit on query parameters?
|
2010-10-19 08:14:41 +08:00
|
|
|
supports_1000_query_parameters = True
|
2010-10-11 20:55:17 +08:00
|
|
|
|
|
|
|
# Can an object have a primary key of 0? MySQL says No.
|
|
|
|
allows_primary_key_0 = True
|
|
|
|
|
2010-11-10 00:46:42 +08:00
|
|
|
# Do we need to NULL a ForeignKey out, or can the constraint check be
|
|
|
|
# deferred
|
|
|
|
can_defer_constraint_checks = False
|
|
|
|
|
2010-12-22 11:34:04 +08:00
|
|
|
# date_interval_sql can properly handle mixed Date/DateTime fields and timedeltas
|
|
|
|
supports_mixed_date_datetime_comparisons = True
|
|
|
|
|
2011-10-15 05:49:43 +08:00
|
|
|
# Does the backend support tablespaces? Default to False because it isn't
|
|
|
|
# in the SQL standard.
|
|
|
|
supports_tablespaces = False
|
|
|
|
|
2012-05-23 04:46:27 +08:00
|
|
|
# Does the backend reset sequences between tests?
|
|
|
|
supports_sequence_reset = True
|
|
|
|
|
2012-06-09 21:59:52 +08:00
|
|
|
# Confirm support for introspected foreign keys
|
|
|
|
# Every database can do this reliably, except MySQL,
|
|
|
|
# which can't do it for MyISAM tables
|
|
|
|
can_introspect_foreign_keys = True
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2011-12-23 04:42:40 +08:00
|
|
|
# Support for the DISTINCT ON clause
|
|
|
|
can_distinct_on_fields = False
|
|
|
|
|
2013-03-05 05:17:35 +08:00
|
|
|
# Does the backend decide to commit before SAVEPOINT statements
|
|
|
|
# when autocommit is disabled? http://bugs.python.org/issue8145#msg109965
|
|
|
|
autocommits_when_autocommit_is_off = False
|
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
|
|
|
|
2012-06-09 21:59:52 +08:00
|
|
|
@cached_property
|
|
|
|
def supports_transactions(self):
|
2010-10-11 20:55:17 +08:00
|
|
|
"Confirm support for transactions"
|
2012-05-27 07:24:57 +08:00
|
|
|
try:
|
|
|
|
# Make sure to run inside a managed transaction block,
|
|
|
|
# otherwise autocommit will cause the confimation to
|
|
|
|
# fail.
|
|
|
|
self.connection.enter_transaction_management()
|
|
|
|
cursor = self.connection.cursor()
|
|
|
|
cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
|
2013-02-20 09:11:54 +08:00
|
|
|
self.connection.commit()
|
2012-05-27 07:24:57 +08:00
|
|
|
cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)')
|
2013-02-20 09:11:54 +08:00
|
|
|
self.connection.rollback()
|
2012-05-27 07:24:57 +08:00
|
|
|
cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST')
|
|
|
|
count, = cursor.fetchone()
|
|
|
|
cursor.execute('DROP TABLE ROLLBACK_TEST')
|
2013-02-20 09:11:54 +08:00
|
|
|
self.connection.commit()
|
2012-05-27 07:24:57 +08:00
|
|
|
finally:
|
|
|
|
self.connection.leave_transaction_management()
|
2010-10-11 20:55:17 +08:00
|
|
|
return count == 0
|
|
|
|
|
2012-06-09 21:59:52 +08:00
|
|
|
@cached_property
|
|
|
|
def supports_stddev(self):
|
2010-10-11 20:55:17 +08:00
|
|
|
"Confirm support for STDDEV and related stats functions"
|
|
|
|
class StdDevPop(object):
|
|
|
|
sql_function = 'STDDEV_POP'
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.connection.ops.check_aggregate_support(StdDevPop())
|
2012-05-18 18:08:36 +08:00
|
|
|
return True
|
2010-10-28 10:59:22 +08:00
|
|
|
except NotImplementedError:
|
2012-05-18 18:08:36 +08:00
|
|
|
return False
|
2010-10-11 20:55:17 +08:00
|
|
|
|
|
|
|
|
2007-08-20 06:29:57 +08:00
|
|
|
class BaseDatabaseOperations(object):
|
|
|
|
"""
|
|
|
|
This class encapsulates all backend-specific differences, such as the way
|
|
|
|
a backend performs ordering or calculates the ID of a recently-inserted
|
|
|
|
row.
|
|
|
|
"""
|
2009-12-22 23:18:51 +08:00
|
|
|
compiler_module = "django.db.models.sql.compiler"
|
|
|
|
|
2011-04-05 08:19:17 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
2011-01-12 21:39:31 +08:00
|
|
|
self._cache = None
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2007-09-15 02:12:36 +08:00
|
|
|
def autoinc_sql(self, table, column):
|
2007-08-20 06:29:57 +08:00
|
|
|
"""
|
|
|
|
Returns any SQL needed to support auto-incrementing primary keys, or
|
|
|
|
None if no SQL is necessary.
|
|
|
|
|
|
|
|
This SQL is executed when a table is created.
|
|
|
|
"""
|
|
|
|
return None
|
2007-08-20 06:40:06 +08:00
|
|
|
|
2012-04-29 09:22:05 +08:00
|
|
|
def bulk_batch_size(self, fields, objs):
|
|
|
|
"""
|
|
|
|
Returns the maximum allowed batch size for the backend. The fields
|
|
|
|
are the fields going to be inserted in the batch, the objs contains
|
|
|
|
all the objects to be inserted.
|
|
|
|
"""
|
|
|
|
return len(objs)
|
|
|
|
|
2012-07-05 22:20:48 +08:00
|
|
|
def cache_key_culling_sql(self):
|
|
|
|
"""
|
|
|
|
Returns a SQL query that retrieves the first cache key greater than the
|
|
|
|
n smallest.
|
|
|
|
|
|
|
|
This is used by the 'db' cache backend to determine where to start
|
|
|
|
culling.
|
|
|
|
"""
|
|
|
|
return "SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s"
|
|
|
|
|
2007-08-20 06:40:06 +08:00
|
|
|
def date_extract_sql(self, lookup_type, field_name):
|
|
|
|
"""
|
|
|
|
Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
|
|
|
|
extracts a value from the given date field field_name.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
2007-08-20 06:47:43 +08:00
|
|
|
|
2010-12-22 11:34:04 +08:00
|
|
|
def date_interval_sql(self, sql, connector, timedelta):
|
|
|
|
"""
|
|
|
|
Implements the date interval functionality for expressions
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2007-08-20 06:47:43 +08:00
|
|
|
def date_trunc_sql(self, lookup_type, field_name):
|
|
|
|
"""
|
|
|
|
Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
|
2013-02-10 23:15:49 +08:00
|
|
|
truncates the given date field field_name to a date object with only
|
2007-08-20 06:47:43 +08:00
|
|
|
the given specificity.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
2007-08-20 06:55:05 +08:00
|
|
|
|
|
|
|
def datetime_cast_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL necessary to cast a datetime value so that it will be
|
|
|
|
retrieved as a Python datetime object instead of a string.
|
2007-08-20 06:57:08 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
This SQL should include a '%s' in place of the field's name.
|
2007-08-20 06:55:05 +08:00
|
|
|
"""
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
return "%s"
|
2007-08-20 07:03:38 +08:00
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
def datetime_extract_sql(self, lookup_type, field_name, tzname):
|
|
|
|
"""
|
|
|
|
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute' or
|
|
|
|
'second', returns the SQL that extracts a value from the given
|
|
|
|
datetime field field_name, and a tuple of parameters.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def datetime_trunc_sql(self, lookup_type, field_name, tzname):
|
|
|
|
"""
|
|
|
|
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute' or
|
|
|
|
'second', returns the SQL that truncates the given datetime field
|
|
|
|
field_name to a datetime object with only the given specificity, and
|
|
|
|
a tuple of parameters.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2007-08-20 07:03:38 +08:00
|
|
|
def deferrable_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL necessary to make a constraint "initially deferred"
|
|
|
|
during a CREATE TABLE statement.
|
|
|
|
"""
|
|
|
|
return ''
|
2007-08-20 07:07:34 +08:00
|
|
|
|
2012-04-29 09:22:05 +08:00
|
|
|
def distinct_sql(self, fields):
|
|
|
|
"""
|
|
|
|
Returns an SQL DISTINCT clause which removes duplicate rows from the
|
|
|
|
result set. If any fields are given, only the given fields are being
|
|
|
|
checked for duplicates.
|
|
|
|
"""
|
|
|
|
if fields:
|
|
|
|
raise NotImplementedError('DISTINCT ON fields is not supported by this database backend')
|
|
|
|
else:
|
|
|
|
return 'DISTINCT'
|
|
|
|
|
2007-08-20 07:07:34 +08:00
|
|
|
def drop_foreignkey_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL command that drops a foreign key.
|
|
|
|
"""
|
|
|
|
return "DROP CONSTRAINT"
|
2007-08-20 07:13:06 +08:00
|
|
|
|
2007-08-20 11:08:32 +08:00
|
|
|
def drop_sequence_sql(self, table):
|
|
|
|
"""
|
|
|
|
Returns any SQL necessary to drop the sequence for the given table.
|
|
|
|
Returns None if no SQL is necessary.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2009-03-13 07:41:27 +08:00
|
|
|
def fetch_returned_insert_id(self, cursor):
|
|
|
|
"""
|
|
|
|
Given a cursor object that has just performed an INSERT...RETURNING
|
|
|
|
statement into a table that has an auto-incrementing ID, returns the
|
|
|
|
newly created ID.
|
|
|
|
"""
|
|
|
|
return cursor.fetchone()[0]
|
|
|
|
|
2007-08-20 11:03:40 +08:00
|
|
|
def field_cast_sql(self, db_type):
|
|
|
|
"""
|
|
|
|
Given a column type (e.g. 'BLOB', 'VARCHAR'), returns the SQL necessary
|
|
|
|
to cast it before using it in a WHERE statement. Note that the
|
|
|
|
resulting string should contain a '%s' placeholder for the column being
|
|
|
|
searched against.
|
|
|
|
"""
|
|
|
|
return '%s'
|
|
|
|
|
2008-12-10 13:19:27 +08:00
|
|
|
def force_no_ordering(self):
|
|
|
|
"""
|
|
|
|
Returns a list used in the "ORDER BY" clause to force no ordering at
|
|
|
|
all. Returning an empty list means that nothing will be included in the
|
|
|
|
ordering.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2011-04-21 04:42:07 +08:00
|
|
|
def for_update_sql(self, nowait=False):
|
|
|
|
"""
|
|
|
|
Returns the FOR UPDATE SQL clause to lock rows for an update operation.
|
|
|
|
"""
|
|
|
|
if nowait:
|
|
|
|
return 'FOR UPDATE NOWAIT'
|
|
|
|
else:
|
|
|
|
return 'FOR UPDATE'
|
|
|
|
|
2007-08-20 07:13:06 +08:00
|
|
|
def fulltext_search_sql(self, field_name):
|
|
|
|
"""
|
|
|
|
Returns the SQL WHERE clause to use in order to perform a full-text
|
|
|
|
search of the given field_name. Note that the resulting string should
|
|
|
|
contain a '%s' placeholder for the value being searched against.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError('Full-text search is not implemented for this database backend')
|
2007-08-20 07:18:43 +08:00
|
|
|
|
2007-10-24 03:00:31 +08:00
|
|
|
def last_executed_query(self, cursor, sql, params):
|
|
|
|
"""
|
|
|
|
Returns a string of the query last executed by the given cursor, with
|
|
|
|
placeholders replaced with actual values.
|
|
|
|
|
|
|
|
`sql` is the raw query containing placeholders, and `params` is the
|
|
|
|
sequence of parameters. These are used by default, but this method
|
|
|
|
exists for database backends to provide a better implementation
|
|
|
|
according to their own quoting schemes.
|
|
|
|
"""
|
2012-08-30 04:40:51 +08:00
|
|
|
from django.utils.encoding import force_text
|
2007-10-24 03:00:31 +08:00
|
|
|
|
|
|
|
# Convert params to contain Unicode values.
|
2012-07-21 16:00:10 +08:00
|
|
|
to_unicode = lambda s: force_text(s, strings_only=True, errors='replace')
|
2007-10-24 03:00:31 +08:00
|
|
|
if isinstance(params, (list, tuple)):
|
2013-01-27 00:51:44 +08:00
|
|
|
u_params = tuple(to_unicode(val) for val in params)
|
2007-10-24 03:00:31 +08:00
|
|
|
else:
|
2013-01-27 00:51:44 +08:00
|
|
|
u_params = dict((to_unicode(k), to_unicode(v)) for k, v in params.items())
|
2007-10-24 03:00:31 +08:00
|
|
|
|
2013-01-27 00:51:44 +08:00
|
|
|
return six.text_type("QUERY = %r - PARAMS = %r") % (sql, u_params)
|
2007-10-24 03:00:31 +08:00
|
|
|
|
2007-08-20 07:18:43 +08:00
|
|
|
def last_insert_id(self, cursor, table_name, pk_name):
|
|
|
|
"""
|
|
|
|
Given a cursor object that has just performed an INSERT statement into
|
|
|
|
a table that has an auto-incrementing ID, returns the newly created ID.
|
|
|
|
|
|
|
|
This method also receives the table name and the name of the primary-key
|
|
|
|
column.
|
|
|
|
"""
|
|
|
|
return cursor.lastrowid
|
2007-08-20 07:24:59 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def lookup_cast(self, lookup_type):
|
|
|
|
"""
|
|
|
|
Returns the string to use in a query when performing lookups
|
|
|
|
("contains", "like", etc). The resulting string should contain a '%s'
|
|
|
|
placeholder for the column being searched against.
|
|
|
|
"""
|
|
|
|
return "%s"
|
|
|
|
|
2010-09-17 03:53:41 +08:00
|
|
|
def max_in_list_size(self):
|
|
|
|
"""
|
|
|
|
Returns the maximum number of items that can be passed in a single 'IN'
|
|
|
|
list condition, or None if the backend does not impose a limit.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2007-08-20 07:53:39 +08:00
|
|
|
def max_name_length(self):
|
|
|
|
"""
|
|
|
|
Returns the maximum length of table and column names, or None if there
|
|
|
|
is no limit.
|
|
|
|
"""
|
|
|
|
return None
|
2007-08-20 07:59:06 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def no_limit_value(self):
|
|
|
|
"""
|
|
|
|
Returns the value to use for the LIMIT when we are wanting "LIMIT
|
|
|
|
infinity". Returns None if the limit clause can be omitted in this case.
|
|
|
|
"""
|
2009-03-10 19:21:46 +08:00
|
|
|
raise NotImplementedError
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2007-08-20 07:59:06 +08:00
|
|
|
def pk_default_value(self):
|
|
|
|
"""
|
|
|
|
Returns the value to use during an INSERT statement to specify that
|
|
|
|
the field should use its default value.
|
|
|
|
"""
|
|
|
|
return 'DEFAULT'
|
2007-08-20 08:04:20 +08:00
|
|
|
|
2009-03-14 05:04:48 +08:00
|
|
|
def process_clob(self, value):
|
|
|
|
"""
|
|
|
|
Returns the value of a CLOB column, for backends that return a locator
|
|
|
|
object that requires additional processing.
|
|
|
|
"""
|
|
|
|
return value
|
|
|
|
|
2009-03-11 15:06:50 +08:00
|
|
|
def return_insert_id(self):
|
|
|
|
"""
|
2009-03-13 07:41:27 +08:00
|
|
|
For backends that support returning the last insert ID as part
|
|
|
|
of an insert query, this method returns the SQL and params to
|
|
|
|
append to the INSERT query. The returned fragment should
|
|
|
|
contain a format string to hold the appropriate column.
|
2009-03-11 15:06:50 +08:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def compiler(self, compiler_name):
|
2007-08-20 10:39:05 +08:00
|
|
|
"""
|
2009-12-22 23:18:51 +08:00
|
|
|
Returns the SQLCompiler class corresponding to the given name,
|
|
|
|
in the namespace corresponding to the `compiler_module` attribute
|
|
|
|
on this backend.
|
2007-08-20 10:39:05 +08:00
|
|
|
"""
|
2011-01-12 21:39:31 +08:00
|
|
|
if self._cache is None:
|
|
|
|
self._cache = import_module(self.compiler_module)
|
|
|
|
return getattr(self._cache, compiler_name)
|
2007-08-20 10:39:05 +08:00
|
|
|
|
2007-08-20 09:03:33 +08:00
|
|
|
def quote_name(self, name):
|
|
|
|
"""
|
|
|
|
Returns a quoted version of the given table, index or column name. Does
|
|
|
|
not quote the given name if it's already been quoted.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2007-08-20 08:04:20 +08:00
|
|
|
def random_function_sql(self):
|
|
|
|
"""
|
|
|
|
Returns a SQL expression that returns a random value.
|
|
|
|
"""
|
|
|
|
return 'RANDOM()'
|
2007-08-20 08:15:53 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def regex_lookup(self, lookup_type):
|
|
|
|
"""
|
|
|
|
Returns the string to use in a query when performing regular expression
|
|
|
|
lookups (using "regex" or "iregex"). The resulting string should
|
|
|
|
contain a '%s' placeholder for the column being searched against.
|
|
|
|
|
|
|
|
If the feature is not supported (or part of it is not supported), a
|
|
|
|
NotImplementedError exception can be raised.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2008-08-12 13:34:56 +08:00
|
|
|
def savepoint_create_sql(self, sid):
|
|
|
|
"""
|
|
|
|
Returns the SQL for starting a new savepoint. Only required if the
|
|
|
|
"uses_savepoints" feature is True. The "sid" parameter is a string
|
|
|
|
for the savepoint id.
|
|
|
|
"""
|
2013-03-01 01:30:03 +08:00
|
|
|
return "SAVEPOINT %s" % self.quote_name(sid)
|
2008-08-12 13:34:56 +08:00
|
|
|
|
|
|
|
def savepoint_commit_sql(self, sid):
|
|
|
|
"""
|
|
|
|
Returns the SQL for committing the given savepoint.
|
|
|
|
"""
|
2013-03-01 01:30:03 +08:00
|
|
|
return "RELEASE SAVEPOINT %s" % self.quote_name(sid)
|
2008-08-12 13:34:56 +08:00
|
|
|
|
|
|
|
def savepoint_rollback_sql(self, sid):
|
|
|
|
"""
|
|
|
|
Returns the SQL for rolling back the given savepoint.
|
|
|
|
"""
|
2013-03-01 01:30:03 +08:00
|
|
|
return "ROLLBACK TO SAVEPOINT %s" % self.quote_name(sid)
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2012-03-14 07:29:15 +08:00
|
|
|
def set_time_zone_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL that will set the connection's time zone.
|
|
|
|
|
|
|
|
Returns '' if the backend doesn't support time zones.
|
|
|
|
"""
|
|
|
|
return ''
|
|
|
|
|
2007-08-20 08:15:53 +08:00
|
|
|
def sql_flush(self, style, tables, sequences):
|
|
|
|
"""
|
|
|
|
Returns a list of SQL statements required to remove all data from
|
|
|
|
the given database tables (without actually removing the tables
|
|
|
|
themselves).
|
|
|
|
|
2012-07-25 04:24:16 +08:00
|
|
|
The returned value also includes SQL statements required to reset DB
|
|
|
|
sequences passed in :param sequences:.
|
|
|
|
|
2007-08-20 08:15:53 +08:00
|
|
|
The `style` argument is a Style object as returned by either
|
|
|
|
color_style() or no_style() in django.core.management.color.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
2007-08-20 08:21:10 +08:00
|
|
|
|
2012-07-25 04:24:16 +08:00
|
|
|
def sequence_reset_by_name_sql(self, style, sequences):
|
|
|
|
"""
|
|
|
|
Returns a list of the SQL statements required to reset sequences
|
|
|
|
passed in :param sequences:.
|
|
|
|
|
|
|
|
The `style` argument is a Style object as returned by either
|
|
|
|
color_style() or no_style() in django.core.management.color.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2007-08-20 08:21:10 +08:00
|
|
|
def sequence_reset_sql(self, style, model_list):
|
|
|
|
"""
|
|
|
|
Returns a list of the SQL statements required to reset sequences for
|
|
|
|
the given models.
|
|
|
|
|
|
|
|
The `style` argument is a Style object as returned by either
|
|
|
|
color_style() or no_style() in django.core.management.color.
|
|
|
|
"""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
return [] # No sequence reset required by default.
|
2007-08-20 08:24:03 +08:00
|
|
|
|
|
|
|
def start_transaction_sql(self):
|
|
|
|
"""
|
|
|
|
Returns the SQL statement required to start a transaction.
|
|
|
|
"""
|
|
|
|
return "BEGIN;"
|
2007-08-20 08:30:19 +08:00
|
|
|
|
2010-05-28 21:46:12 +08:00
|
|
|
def end_transaction_sql(self, success=True):
|
2013-03-05 05:17:35 +08:00
|
|
|
"""
|
|
|
|
Returns the SQL statement required to end a transaction.
|
|
|
|
"""
|
2010-05-28 21:46:12 +08:00
|
|
|
if not success:
|
|
|
|
return "ROLLBACK;"
|
|
|
|
return "COMMIT;"
|
|
|
|
|
2008-09-11 07:03:07 +08:00
|
|
|
def tablespace_sql(self, tablespace, inline=False):
|
2007-08-20 08:30:19 +08:00
|
|
|
"""
|
2011-10-15 05:49:43 +08:00
|
|
|
Returns the SQL that will be used in a query to define the tablespace.
|
|
|
|
|
|
|
|
Returns '' if the backend doesn't support tablespaces.
|
|
|
|
|
|
|
|
If inline is True, the SQL is appended to a row; otherwise it's appended
|
|
|
|
to the entire CREATE TABLE or CREATE INDEX statement.
|
2007-08-20 08:30:19 +08:00
|
|
|
"""
|
2008-08-11 20:11:25 +08:00
|
|
|
return ''
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2008-06-16 11:15:04 +08:00
|
|
|
def prep_for_like_query(self, x):
|
|
|
|
"""Prepares a value for use in a LIKE query."""
|
2012-08-30 04:40:51 +08:00
|
|
|
from django.utils.encoding import force_text
|
|
|
|
return force_text(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2008-08-28 13:42:05 +08:00
|
|
|
# Same as prep_for_like_query(), but called for "iexact" matches, which
|
|
|
|
# need not necessarily be implemented using "LIKE" in the backend.
|
|
|
|
prep_for_iexact_query = prep_for_like_query
|
|
|
|
|
2012-04-25 02:03:14 +08:00
|
|
|
def validate_autopk_value(self, value):
|
|
|
|
"""
|
|
|
|
Certain backends do not accept some values for "serial" fields
|
|
|
|
(for example zero in MySQL). This method will raise a ValueError
|
|
|
|
if the value is invalid, otherwise returns validated value.
|
|
|
|
"""
|
|
|
|
return value
|
|
|
|
|
2008-07-29 13:09:29 +08:00
|
|
|
def value_to_db_date(self, value):
|
|
|
|
"""
|
|
|
|
Transform a date value to an object compatible with what is expected
|
|
|
|
by the backend driver for date columns.
|
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
2012-07-20 20:48:51 +08:00
|
|
|
return six.text_type(value)
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
def value_to_db_datetime(self, value):
|
|
|
|
"""
|
|
|
|
Transform a datetime value to an object compatible with what is expected
|
2008-07-30 11:16:39 +08:00
|
|
|
by the backend driver for datetime columns.
|
2008-07-29 13:09:29 +08:00
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
2012-07-20 20:48:51 +08:00
|
|
|
return six.text_type(value)
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
def value_to_db_time(self, value):
|
|
|
|
"""
|
2011-10-14 03:23:45 +08:00
|
|
|
Transform a time value to an object compatible with what is expected
|
2008-07-30 11:16:39 +08:00
|
|
|
by the backend driver for time columns.
|
2008-07-29 13:09:29 +08:00
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
2013-02-10 23:15:49 +08:00
|
|
|
if timezone.is_aware(value):
|
2011-11-18 21:01:06 +08:00
|
|
|
raise ValueError("Django does not support timezone-aware times.")
|
2012-07-20 20:48:51 +08:00
|
|
|
return six.text_type(value)
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
def value_to_db_decimal(self, value, max_digits, decimal_places):
|
|
|
|
"""
|
|
|
|
Transform a decimal.Decimal value to an object compatible with what is
|
|
|
|
expected by the backend driver for decimal (numeric) columns.
|
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
|
|
|
return util.format_number(value, max_digits, decimal_places)
|
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
def year_lookup_bounds_for_date_field(self, value):
|
2008-07-29 13:09:29 +08:00
|
|
|
"""
|
|
|
|
Returns a two-elements list with the lower and upper bound to be used
|
2013-02-10 23:15:49 +08:00
|
|
|
with a BETWEEN operator to query a DateField value using a year
|
|
|
|
lookup.
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
`value` is an int, containing the looked-up year.
|
|
|
|
"""
|
2013-02-10 23:15:49 +08:00
|
|
|
first = datetime.date(value, 1, 1)
|
|
|
|
second = datetime.date(value, 12, 31)
|
|
|
|
return [first, second]
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
def year_lookup_bounds_for_datetime_field(self, value):
|
2008-07-29 13:09:29 +08:00
|
|
|
"""
|
|
|
|
Returns a two-elements list with the lower and upper bound to be used
|
2013-02-10 23:15:49 +08:00
|
|
|
with a BETWEEN operator to query a DateTimeField value using a year
|
|
|
|
lookup.
|
2008-07-29 13:09:29 +08:00
|
|
|
|
|
|
|
`value` is an int, containing the looked-up year.
|
|
|
|
"""
|
2013-02-10 23:15:49 +08:00
|
|
|
first = datetime.datetime(value, 1, 1)
|
|
|
|
second = datetime.datetime(value, 12, 31, 23, 59, 59, 999999)
|
|
|
|
if settings.USE_TZ:
|
|
|
|
tz = timezone.get_current_timezone()
|
|
|
|
first = timezone.make_aware(first, tz)
|
|
|
|
second = timezone.make_aware(second, tz)
|
|
|
|
return [first, second]
|
2008-07-29 13:09:29 +08:00
|
|
|
|
2009-01-15 19:06:34 +08:00
|
|
|
def convert_values(self, value, field):
|
2012-07-15 19:41:05 +08:00
|
|
|
"""
|
|
|
|
Coerce the value returned by the database backend into a consistent type
|
|
|
|
that is compatible with the field type.
|
2009-01-15 19:06:34 +08:00
|
|
|
"""
|
2012-12-17 04:24:15 +08:00
|
|
|
if value is None:
|
2009-01-15 19:06:34 +08:00
|
|
|
return value
|
2012-12-17 04:24:15 +08:00
|
|
|
internal_type = field.get_internal_type()
|
|
|
|
if internal_type == 'FloatField':
|
2012-08-13 14:15:20 +08:00
|
|
|
return float(value)
|
2012-07-15 19:41:05 +08:00
|
|
|
elif (internal_type and (internal_type.endswith('IntegerField')
|
|
|
|
or internal_type == 'AutoField')):
|
2009-01-15 19:06:34 +08:00
|
|
|
return int(value)
|
2012-07-15 19:41:05 +08:00
|
|
|
return value
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2009-02-02 20:03:31 +08:00
|
|
|
def check_aggregate_support(self, aggregate_func):
|
|
|
|
"""Check that the backend supports the provided aggregate
|
|
|
|
|
|
|
|
This is used on specific backends to rule out known aggregates
|
|
|
|
that are known to have faulty implementations. If the named
|
|
|
|
aggregate function has a known problem, the backend should
|
2011-10-05 17:54:01 +08:00
|
|
|
raise NotImplementedError.
|
2009-02-02 20:03:31 +08:00
|
|
|
"""
|
|
|
|
pass
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2009-02-24 19:15:31 +08:00
|
|
|
def combine_expression(self, connector, sub_expressions):
|
|
|
|
"""Combine a list of subexpressions into a single expression, using
|
|
|
|
the provided connecting operator. This is required because operators
|
|
|
|
can vary between backends (e.g., Oracle with %% and &) and between
|
|
|
|
subexpression types (e.g., date expressions)
|
|
|
|
"""
|
|
|
|
conn = ' %s ' % connector
|
|
|
|
return conn.join(sub_expressions)
|
|
|
|
|
2012-11-15 20:23:02 +08:00
|
|
|
def modify_insert_params(self, placeholders, params):
|
|
|
|
"""Allow modification of insert parameters. Needed for Oracle Spatial
|
|
|
|
backend due to #10888.
|
|
|
|
"""
|
|
|
|
return params
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
|
2013-01-13 04:10:08 +08:00
|
|
|
|
|
|
|
# Structure returned by the DB-API cursor.description interface (PEP 249)
|
|
|
|
FieldInfo = namedtuple('FieldInfo',
|
|
|
|
'name type_code display_size internal_size precision scale null_ok'
|
|
|
|
)
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class BaseDatabaseIntrospection(object):
|
|
|
|
"""
|
|
|
|
This class encapsulates all backend-specific introspection utilities
|
|
|
|
"""
|
|
|
|
data_types_reverse = {}
|
|
|
|
|
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
|
|
|
|
2009-08-22 05:42:39 +08:00
|
|
|
def get_field_type(self, data_type, description):
|
|
|
|
"""Hook for a database backend to use the cursor description to
|
|
|
|
match a Django field type to a database column.
|
|
|
|
|
|
|
|
For Oracle, the column data_type on its own is insufficient to
|
|
|
|
distinguish between a FloatField and IntegerField, for example."""
|
|
|
|
return self.data_types_reverse[data_type]
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def table_name_converter(self, name):
|
|
|
|
"""Apply a conversion to the name for the purposes of comparison.
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
The default table name converter is for case sensitive comparison.
|
|
|
|
"""
|
|
|
|
return name
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2012-04-29 07:11:55 +08:00
|
|
|
def table_names(self, cursor=None):
|
|
|
|
"""
|
|
|
|
Returns a list of names of all tables that exist in the database.
|
|
|
|
The returned table list is sorted by Python's default sorting. We
|
|
|
|
do NOT use database's ORDER BY here to avoid subtle differences
|
|
|
|
in sorting order between databases.
|
|
|
|
"""
|
|
|
|
if cursor is None:
|
|
|
|
cursor = self.connection.cursor()
|
|
|
|
return sorted(self.get_table_list(cursor))
|
|
|
|
|
|
|
|
def get_table_list(self, cursor):
|
|
|
|
"""
|
|
|
|
Returns an unsorted list of names of all tables that exist in the
|
|
|
|
database.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
def django_table_names(self, only_existing=False):
|
|
|
|
"""
|
|
|
|
Returns a list of all table names that have associated Django models and
|
|
|
|
are in INSTALLED_APPS.
|
|
|
|
|
|
|
|
If only_existing is True, the resulting list will only include the tables
|
|
|
|
that actually exist in the database.
|
|
|
|
"""
|
2010-03-10 21:43:23 +08:00
|
|
|
from django.db import models, router
|
2008-08-11 20:11:25 +08:00
|
|
|
tables = set()
|
|
|
|
for app in models.get_apps():
|
|
|
|
for model in models.get_models(app):
|
2009-03-09 11:35:02 +08:00
|
|
|
if not model._meta.managed:
|
|
|
|
continue
|
2010-03-10 21:43:23 +08:00
|
|
|
if not router.allow_syncdb(self.connection.alias, model):
|
|
|
|
continue
|
2008-08-11 20:11:25 +08:00
|
|
|
tables.add(model._meta.db_table)
|
|
|
|
tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
|
2012-02-12 06:12:49 +08:00
|
|
|
tables = list(tables)
|
2008-08-11 20:11:25 +08:00
|
|
|
if only_existing:
|
2010-10-31 08:53:58 +08:00
|
|
|
existing_tables = self.table_names()
|
|
|
|
tables = [
|
|
|
|
t
|
|
|
|
for t in tables
|
|
|
|
if self.table_name_converter(t) in existing_tables
|
|
|
|
]
|
2008-08-11 20:11:25 +08:00
|
|
|
return tables
|
|
|
|
|
|
|
|
def installed_models(self, tables):
|
|
|
|
"Returns a set of all models represented by the provided list of table names."
|
2010-03-10 21:43:23 +08:00
|
|
|
from django.db import models, router
|
2008-08-11 20:11:25 +08:00
|
|
|
all_models = []
|
|
|
|
for app in models.get_apps():
|
|
|
|
for model in models.get_models(app):
|
2010-03-10 21:43:23 +08:00
|
|
|
if router.allow_syncdb(self.connection.alias, model):
|
|
|
|
all_models.append(model)
|
2012-08-16 14:08:45 +08:00
|
|
|
tables = list(map(self.table_name_converter, tables))
|
2010-11-02 13:41:46 +08:00
|
|
|
return set([
|
|
|
|
m for m in all_models
|
|
|
|
if self.table_name_converter(m._meta.db_table) in tables
|
2008-08-11 20:11:25 +08:00
|
|
|
])
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def sequence_list(self):
|
|
|
|
"Returns a list of information about all DB sequences for all models in all apps."
|
2010-03-10 21:43:23 +08:00
|
|
|
from django.db import models, router
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
apps = models.get_apps()
|
|
|
|
sequence_list = []
|
|
|
|
|
|
|
|
for app in apps:
|
|
|
|
for model in models.get_models(app):
|
2009-03-09 11:35:02 +08:00
|
|
|
if not model._meta.managed:
|
|
|
|
continue
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
if model._meta.swapped:
|
|
|
|
continue
|
2010-03-10 21:43:23 +08:00
|
|
|
if not router.allow_syncdb(self.connection.alias, model):
|
|
|
|
continue
|
2008-08-11 20:11:25 +08:00
|
|
|
for f in model._meta.local_fields:
|
|
|
|
if isinstance(f, models.AutoField):
|
|
|
|
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
break # Only one AutoField is allowed per model, so don't bother continuing.
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
for f in model._meta.local_many_to_many:
|
2009-04-13 15:07:51 +08:00
|
|
|
# If this is an m2m using an intermediate table,
|
|
|
|
# we don't need to reset the sequence.
|
|
|
|
if f.rel.through is None:
|
|
|
|
sequence_list.append({'table': f.m2m_db_table(), 'column': None})
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
return sequence_list
|
2008-08-12 13:34:56 +08:00
|
|
|
|
2011-08-07 08:43:26 +08:00
|
|
|
def get_key_columns(self, cursor, table_name):
|
|
|
|
"""
|
|
|
|
Backends can override this to return a list of (column_name, referenced_table_name,
|
|
|
|
referenced_column_name) for all key columns in given table.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def get_primary_key_column(self, cursor, table_name):
|
|
|
|
"""
|
2012-09-08 16:24:13 +08:00
|
|
|
Returns the name of the primary key column for the given table.
|
2011-08-07 08:43:26 +08:00
|
|
|
"""
|
2012-09-08 16:24:13 +08:00
|
|
|
for column in six.iteritems(self.get_indexes(cursor, table_name)):
|
|
|
|
if column[1]['primary_key']:
|
|
|
|
return column[0]
|
|
|
|
return None
|
2011-08-07 08:43:26 +08:00
|
|
|
|
2012-04-30 19:05:30 +08:00
|
|
|
def get_indexes(self, cursor, table_name):
|
|
|
|
"""
|
|
|
|
Returns a dictionary of indexed fieldname -> infodict for the given
|
|
|
|
table, where each infodict is in the format:
|
|
|
|
{'primary_key': boolean representing whether it's the primary key,
|
|
|
|
'unique': boolean representing whether it's a unique index}
|
|
|
|
|
|
|
|
Only single-column indexes are introspected.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class BaseDatabaseClient(object):
|
|
|
|
"""
|
2008-09-09 10:13:58 +08:00
|
|
|
This class encapsulates all backend-specific methods for opening a
|
|
|
|
client shell.
|
2008-08-11 20:11:25 +08:00
|
|
|
"""
|
2008-09-09 10:13:58 +08:00
|
|
|
# This should be a string representing the name of the executable
|
|
|
|
# (e.g., "psql"). Subclasses must override this.
|
|
|
|
executable_name = None
|
|
|
|
|
2009-03-11 11:39:34 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
# connection is an instance of BaseDatabaseWrapper.
|
|
|
|
self.connection = connection
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def runshell(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class BaseDatabaseValidation(object):
|
|
|
|
"""
|
|
|
|
This class encapsualtes all backend-specific model validation.
|
|
|
|
"""
|
2009-12-22 23:18:51 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def validate_field(self, errors, opts, f):
|
|
|
|
"By default, there is no backend-specific validation"
|
|
|
|
pass
|