Author: Alex Date: 2009-07-19 16:57:08 -0500 (Sun, 19 Jul 2009) New Revision: 11273
Modified: django/branches/soc2009/multidb/TODO.txt django/branches/soc2009/multidb/django/db/models/fields/__init__.py django/branches/soc2009/multidb/django/db/models/fields/related.py django/branches/soc2009/multidb/django/db/models/query.py django/branches/soc2009/multidb/tests/regressiontests/multiple_database/tests.py Log: [soc2009/multidb] Raise an exception at an attempt to do a subquery with 2 different databases. Eventually we'll just evaluate the 2 queries seperates. Modified: django/branches/soc2009/multidb/TODO.txt =================================================================== --- django/branches/soc2009/multidb/TODO.txt 2009-07-19 21:31:13 UTC (rev 11272) +++ django/branches/soc2009/multidb/TODO.txt 2009-07-19 21:57:08 UTC (rev 11273) @@ -14,12 +14,12 @@ flush, reset, and syncdb need to not prompt the user multiple times. -3) Handle nesting of Querysets using __in across multiple dbs. +3) Handle backends with custom Query classes. -4) Handle backends with custom Query classes. +4) Wait on the merge of the m2m stuff. -5) Wait on the merge of the m2m stuff. +5) Fix django.contrib.gis, it's broken in all sorts of ways. -6) Fix django.contrib.gis, it's broken in all sorts of ways. +6) Generate SQL, instead of an error for nesting on different DBs. 7) Time permitting add support for a ``DatabaseManager``. Modified: django/branches/soc2009/multidb/django/db/models/fields/__init__.py =================================================================== --- django/branches/soc2009/multidb/django/db/models/fields/__init__.py 2009-07-19 21:31:13 UTC (rev 11272) +++ django/branches/soc2009/multidb/django/db/models/fields/__init__.py 2009-07-19 21:57:08 UTC (rev 11273) @@ -201,9 +201,9 @@ if hasattr(value, 'relabel_aliases'): return value if hasattr(value, 'as_sql'): - sql, params = value.as_sql() + sql, params = value.as_sql(connection) else: - sql, params = value._as_sql() + sql, params = value._as_sql(connection) return QueryWrapper(('(%s)' % sql), params) Modified: django/branches/soc2009/multidb/django/db/models/fields/related.py =================================================================== --- django/branches/soc2009/multidb/django/db/models/fields/related.py 2009-07-19 21:31:13 UTC (rev 11272) +++ django/branches/soc2009/multidb/django/db/models/fields/related.py 2009-07-19 21:57:08 UTC (rev 11273) @@ -149,9 +149,9 @@ if hasattr(value, 'relabel_aliases'): return value if hasattr(value, 'as_sql'): - sql, params = value.as_sql() + sql, params = value.as_sql(connection) else: - sql, params = value._as_sql() + sql, params = value._as_sql(connection) return QueryWrapper(('(%s)' % sql), params) # FIXME: lt and gt are explicitally allowed to make Modified: django/branches/soc2009/multidb/django/db/models/query.py =================================================================== --- django/branches/soc2009/multidb/django/db/models/query.py 2009-07-19 21:31:13 UTC (rev 11272) +++ django/branches/soc2009/multidb/django/db/models/query.py 2009-07-19 21:57:08 UTC (rev 11273) @@ -745,12 +745,14 @@ self.query.add_fields(field_names, False) self.query.set_group_by() - def _as_sql(self): + def _as_sql(self, connection): """ Returns the internal query's SQL and parameters (as a tuple). """ obj = self.values("pk") - return obj.query.as_nested_sql() + if connection.settings_dict == obj.query.connection.settings_dict: + return obj.query.as_nested_sql() + raise ValueError("Can't do subqueries with queries on different DBs.") def _validate(self): """ @@ -863,7 +865,7 @@ super(ValuesQuerySet, self)._setup_aggregate_query(aggregates) - def _as_sql(self): + def _as_sql(self, connection): """ For ValueQuerySet (and subclasses like ValuesListQuerySet), they can only be used as nested queries if they're already set up to select only @@ -875,8 +877,12 @@ (not self._fields and len(self.model._meta.fields) > 1)): raise TypeError('Cannot use a multi-field %s as a filter value.' % self.__class__.__name__) - return self._clone().query.as_nested_sql() + obj = self._clone() + if connection.settings_dict == obj.query.connection.settings_dict: + return obj.query.as_nested_sql() + raise ValueError("Can't do subqueries with queries on different DBs.") + def _validate(self): """ Validates that we aren't trying to do a query like Modified: django/branches/soc2009/multidb/tests/regressiontests/multiple_database/tests.py =================================================================== --- django/branches/soc2009/multidb/tests/regressiontests/multiple_database/tests.py 2009-07-19 21:31:13 UTC (rev 11272) +++ django/branches/soc2009/multidb/tests/regressiontests/multiple_database/tests.py 2009-07-19 21:57:08 UTC (rev 11273) @@ -93,3 +93,5 @@ a.delete() self.assertRaises(Article.DoesNotExist, lambda: Article.objects.get(title="Django Rules!")) + self.assertRaises(ValueError, + lambda: list(Article.objects.get(pk__in=Article.objects.using('default')))) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---