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 Initial Version

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

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:

...

  1. elif hasattr(value, 'evaluate'):
  2. # If value is a query expression, evaluate it
  3. value = SQLEvaluator(value, self) ...
  4. 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,

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top