class Product(models.Model):
name = models.CharField(max_length=128)
price = models.DecimalField(max_digits=15, decimal_places=2,
default=0, blank=True)
products = Product.objects.raw(""" SELECT * FROM "products_product" WHERE
price >= %s """, params=[Decimal(200), ])
for product in products:
print product
}}}
this will raise following exception
{{{
#!python
File "site-packages\django\db\models\query.py", line 1219, in __iter__
query = iter(self.query)
File "site-packages\django\db\models\sql\query.py", line 79, in __iter__
self._execute_query()
File "site-packages\django\db\models\sql\query.py", line 106, in
_execute_query
params = tuple(adapter(val) for val in self.params)
File "site-packages\django\db\models\sql\query.py", line 106, in
<genexpr>
params = tuple(adapter(val) for val in self.params)
File "site-packages\django\db\backends\base\operations.py", line 455, in
adapt_unknown_value
return self.adapt_decimalfield_value(value)
TypeError: adapt_decimalfield_value() takes exactly 4 arguments (2 given)
}}}
We are making much more complex query, this is just simple example of bug
we are challenging
--
Ticket URL: <https://code.djangoproject.com/ticket/26219>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Yep, this is indeed a bug. The following patch seems to fix the problem,
but I haven't run the test suite to verify no bad behaviour is introduced.
This is probably a regression introduced in 1.8 (I think). I remember
modifying this code around then.
{{{
diff --git a/django/db/backends/base/operations.py
b/django/db/backends/base/operations.py
index 7957265..10641bf 100644
--- a/django/db/backends/base/operations.py
+++ b/django/db/backends/base/operations.py
@@ -485,7 +485,7 @@ class BaseDatabaseOperations(object):
raise ValueError("Django does not support timezone-aware
times.")
return six.text_type(value)
- def adapt_decimalfield_value(self, value, max_digits,
decimal_places):
+ def adapt_decimalfield_value(self, value, max_digits=None,
decimal_places=None):
"""
Transforms a decimal.Decimal value to an object compatible with
what is
expected by the backend driver for decimal (numeric) columns.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26219#comment:1>
* has_patch: 0 => 1
* severity: Normal => Release blocker
Comment:
Ahh we did a bit of concurrent research!
This is regression introduced by d9521f66b1851b0eacd55bc78f801dc64123e333
in 1.9+.
The proposed patch is what I also had in mind.
--
Ticket URL: <https://code.djangoproject.com/ticket/26219#comment:2>
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26219#comment:3>
* easy: 0 => 1
Comment:
Marking as ''easy picking'' since a test can easily be written from the
report.
--
Ticket URL: <https://code.djangoproject.com/ticket/26219#comment:4>
* owner: nobody => akki
* status: new => assigned
* has_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26219#comment:5>
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/6150
--
Ticket URL: <https://code.djangoproject.com/ticket/26219#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"fdccc02576ae5a524338f65e629948604d80b4c8" fdccc025]:
{{{
#!CommitTicketReference repository=""
revision="fdccc02576ae5a524338f65e629948604d80b4c8"
Fixed #26219 -- Fixed crash when filtering by Decimal in RawQuery.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26219#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"0d2b97ca18b576d1bbff2ccb089527e36d99eaf9" 0d2b97ca]:
{{{
#!CommitTicketReference repository=""
revision="0d2b97ca18b576d1bbff2ccb089527e36d99eaf9"
[1.9.x] Fixed #26219 -- Fixed crash when filtering by Decimal in RawQuery.
Backport of fdccc02576ae5a524338f65e629948604d80b4c8 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26219#comment:8>