Description

There was a private method add_to_query() for objects in add_q(). Using this it was possible for the objects to add themselves to the query's where/having condition. This capability was removed from 1.6 as part of ORM refactorings.

I have seen at least half a dozen complaints/questions about this removal. So, clearly this feature was used more than I anticipated. It will be relatively easy to add similar capability to 1.6, though the API needs to change a little. This will be around 5 lines of code change with practically no risk of regressions. So, I am going to add the capability back unless somebody objects.

The API will likely be add_to_query(query, used_aliases, where_node) where it was previously add_to_query(query, used_aliases). The where_node addition is needed due to other changes in the ORM.

Actually, we likely don't want to add release notes for this one. add_to_query() was internal API and it will remain so. Hopefully we will get official API for .filter(MyCustomFilterCondition(...)) in Django 1.8. If that happens we will likely remove the add_to_query() hack again.

I updated PR 2125 with some more code. Now using add_to_query() objects is also possible and at least somewhat working in HAVING clauses, too.

Using the new version requires some changes to code, but it allows users who relied on add_to_query() to use 1.6 and 1.7. Currently upgrading to 1.6 or 1.7 seems really hard as there doesn't seem to be any viable upgrade path.

This happens with the patch only on py27. py33 seems to be unaffected, and I don't get this error on master. I can't see anything in the patch that should cause this. Another pair of eyes could help spot what is happening here.