diff --git a/TODO.TXT b/TODO.TXT index b8d77fe11a..058079770a 100644 --- a/TODO.TXT +++ b/TODO.TXT @@ -4,10 +4,6 @@ TODO The follow is a list, more or less in the order I intend to do them of things that need to be done. I'm trying to be as granular as possible. -*** -Immediate TODOs: -Finish refactor of WhereNode so that it just takes connection in as_sql. -*** 2) Update all old references to ``settings.DATABASE_*`` to reference ``settings.DATABASES``. This includes the following locations @@ -26,16 +22,8 @@ Finish refactor of WhereNode so that it just takes connection in as_sql. * ``dumpdata``: By default dump the ``default`` database. Later add a ``--database`` flag. - These items will be fixed pending both community consensus, and the API - that will go in that's actually necessary for these to happen. - flush, reset, and syncdb need to not prompt the user multiple times. -9) Fix transaction support. In practice this means changing all the - dictionaries that currently map thread to a boolean to being a dictionary - mapping thread to a set of the affected DBs, and changing all the functions - that use these dictionaries to handle the changes appropriately. - 7) Remove any references to the global ``django.db.connection`` object in the SQL creation process. This includes(but is probably not limited to): @@ -50,6 +38,7 @@ Finish refactor of WhereNode so that it just takes connection in as_sql. 5) Add the ``using`` Meta option. Tests and docs(these are to be assumed at each stage from here on out). + 8) Implement some way to create a new ``Query`` for a different backend when we switch. There are several checks against ``self.connection`` prior to SQL construction, so we either need to defer all these(which will be @@ -67,10 +56,5 @@ Finish refactor of WhereNode so that it just takes connection in as_sql. * ``DateTimeField.get_db_prep_value`` * ``DecimalField.get_db_prep_save`` * ``TimeField.get_db_prep_value`` - * Implementing the command pattern. - * Having the ``QuerySet`` actually store ``Query`` objects for every - database in ``settings.DATABASES`` and do all the operations against - every single one of them, then when it's time excecute the query just - pick the right ``Query`` object to use. This *does* not scale, though it - could probably be done fairly easily. + 10) Time permitting add support for a ``DatabaseManager``. diff --git a/django/db/models/query.py b/django/db/models/query.py index 2c993cfda5..a4fd172ac2 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -284,7 +284,7 @@ class QuerySet(object): and returning the created object. """ obj = self.model(**kwargs) - obj.save(force_insert=True) + obj.save(force_insert=True, using=self._using) return obj def get_or_create(self, **kwargs): diff --git a/django/db/transaction.py b/django/db/transaction.py index 284636dc15..73c5680f7e 100644 --- a/django/db/transaction.py +++ b/django/db/transaction.py @@ -257,8 +257,6 @@ def savepoint_commit(sid, using=None): # DECORATORS # ############## -# TODO update all of these for multi-db - def autocommit(using_or_func=None): """ Decorator that activates commit on save. This is Django's default behavior; diff --git a/tests/regressiontests/multiple_database/tests.py b/tests/regressiontests/multiple_database/tests.py index 3a19469266..f21b873cd3 100644 --- a/tests/regressiontests/multiple_database/tests.py +++ b/tests/regressiontests/multiple_database/tests.py @@ -20,17 +20,11 @@ class DatabaseSettingTestCase(TestCase): class ConnectionTestCase(TestCase): def test_queries(self): - for connection in connections.all(): - qn = connection.ops.quote_name - cursor = connection.cursor() - cursor.execute("""INSERT INTO %(table)s (%(col)s) VALUES (%%s)""" % { - 'table': qn(Book._meta.db_table), - 'col': qn(Book._meta.get_field_by_name('title')[0].column), - }, ('Dive Into Python',)) + for db in connections: + Book.objects.using(db).create(title="Dive into Python") - for connection in connections.all(): - qn = connection.ops.quote_name - cursor = connection.cursor() - cursor.execute("""SELECT * FROM %(table)s""" % {'table': qn(Book._meta.db_table)}) - data = cursor.fetchall() - self.assertEqual('Dive Into Python', data[0][1]) + for db in connections: + books = Book.objects.all().using(db) + self.assertEqual(books.count(), 1) + self.assertEqual(len(books), 1) + self.assertEqual(books[0].title, "Dive into Python")