#26219 closed Bug (fixed)
Cannot filter by DecimalField in RawQuery
Reported by: | jirek | Owned by: | Akshesh Doshi |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9 |
Severity: | Release blocker | Keywords: | DecimalField RawQuery |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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
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
Change History (8)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 9 years ago
Has patch: | set |
---|---|
Severity: | Normal → Release blocker |
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.
comment:3 by , 9 years ago
Needs tests: | set |
---|
comment:4 by , 9 years ago
Easy pickings: | set |
---|
Marking as easy picking since a test can easily be written from the report.
comment:5 by , 9 years ago
Has patch: | unset |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
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.