Author: mtredinnick
Date: 2009-02-28 22:12:30 -0600 (Sat, 28 Feb 2009)
New Revision: 9928
Modified:
django/trunk/django/db/models/fields/__init__.py
django/trunk/django/db/models/fields/related.py
django/trunk/django/db/models/query.py
Log:
To avoid an unfortunately common user-error, rename QuerySet.as_sql().
This was never a public API method, so this is backwards compatible, unless
you're poking at the internals. Refs #10352.
Modified: django/trunk/django/db/models/fields/__init__.py
===================================================================
--- django/trunk/django/db/models/fields/__init__.py 2009-03-01 01:59:18 UTC
(rev 9927)
+++ django/trunk/django/db/models/fields/__init__.py 2009-03-01 04:12:30 UTC
(rev 9928)
@@ -193,12 +193,15 @@
def get_db_prep_lookup(self, lookup_type, value):
"Returns field's value prepared for database lookup."
- if hasattr(value, 'as_sql'):
+ if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'):
# If the value has a relabel_aliases method, it will need to
# be invoked before the final SQL is evaluated
if hasattr(value, 'relabel_aliases'):
return value
- sql, params = value.as_sql()
+ try:
+ sql, params = value.as_sql()
+ except AttributeError:
+ sql, params = value._as_sql()
return QueryWrapper(('(%s)' % sql), params)
if lookup_type in ('regex', 'iregex', 'month', 'day', 'week_day',
'search'):
Modified: django/trunk/django/db/models/fields/related.py
===================================================================
--- django/trunk/django/db/models/fields/related.py 2009-03-01 01:59:18 UTC
(rev 9927)
+++ django/trunk/django/db/models/fields/related.py 2009-03-01 04:12:30 UTC
(rev 9928)
@@ -140,12 +140,15 @@
v = v[0]
return v
- if hasattr(value, 'as_sql'):
+ if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'):
# If the value has a relabel_aliases method, it will need to
# be invoked before the final SQL is evaluated
if hasattr(value, 'relabel_aliases'):
return value
- sql, params = value.as_sql()
+ try:
+ sql, params = value.as_sql()
+ except AttributeError:
+ sql, params = value._as_sql()
return QueryWrapper(('(%s)' % sql), params)
# FIXME: lt and gt are explicitally allowed to make
Modified: django/trunk/django/db/models/query.py
===================================================================
--- django/trunk/django/db/models/query.py 2009-03-01 01:59:18 UTC (rev
9927)
+++ django/trunk/django/db/models/query.py 2009-03-01 04:12:30 UTC (rev
9928)
@@ -703,12 +703,9 @@
self.query.add_fields(field_names, False)
self.query.set_group_by()
- def as_sql(self):
+ def _as_sql(self):
"""
Returns the internal query's SQL and parameters (as a tuple).
-
- This is a private (internal) method. The name is chosen to provide
- uniformity with other interfaces (in particular, the Query class).
"""
obj = self.values("pk")
return obj.query.as_nested_sql()
@@ -812,7 +809,7 @@
super(ValuesQuerySet, self)._setup_aggregate_query(aggregates)
- def as_sql(self):
+ def _as_sql(self):
"""
For ValueQuerySet (and subclasses like ValuesListQuerySet), they can
only be used as nested queries if they're already set up to select only
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---