Opened 15 years ago
Last modified 13 years ago
#13640 closed
add_filter in django/db/models/ sql/query.py causes exception when model have 'evaluate' attribute — at Version 2
Reported by: | LukaszKorzybski | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | net147 | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
I was migrating some django project recently from django 1.0.4 to 1.2.
In Django 1.2/1.1 I found that if model have 'evaluate' attribute then
one will get exception in admin edit page for that model if the page
contains inline forms with related models:
Exception Value: 'Shipper' object has no attribute 'prepare' Exception Location: .../django/db/models/sql/expressions.py in __init__, line 12
It is caused by the fact that add_filter function in django/db/models/sql/query.py does such a check:
... 1005. elif hasattr(value, 'evaluate'): 1006. # If value is a query expression, evaluate it 1007. value = SQLEvaluator(value, self) ... 1008. having_clause = value.contains_aggregate ...
The problem is that "value" in this case is Shipper model which in
have "evaluate" method so it is recognized as query expression here.
Greetings,
Ups I forgot to do some formatting of the text, sorry for that :/