summaryrefslogtreecommitdiff
path: root/django/db/models/sql
AgeCommit message (Collapse)Author
2012-12-30Minor improvement to proxy model handlingAnssi Kääriäinen
Refs #19385
2012-12-30Made use of PathInfo.direct flag in trim_joinsAnssi Kääriäinen
Refs #19385
2012-12-30Added Query.join_parent_model()Anssi Kääriäinen
This simplifies especially compiler.py a lot, where almost the same code was repeated multiple times. Refs #19385
2012-12-30Moved join path generation to FieldAnssi Kääriäinen
Refs #19385
2012-12-30Made sure join_field is always available in .join()Anssi Kääriäinen
Refs #19385
2012-12-20Fixed a regression in distinct_onAnssi Kääriäinen
Caused by regression fix for #19500.
2012-12-20Fixed #18854 -- Join promotion in disjunction casesAnssi Kääriäinen
The added promotion logic is based on promoting any joins used in only some of the childs of an OR clause unless the join existed before the OR clause addition.
2012-12-20Fixed #19500 -- Solved a regression in join reuseAnssi Kääriäinen
The ORM didn't reuse joins for direct foreign key traversals when using chained filters. For example: qs.filter(fk__somefield=1).filter(fk__somefield=2)) produced two joins. As a bonus, reverse onetoone filters can now reuse joins correctly The regression was caused by the join() method refactor in commit 68847135bc9acb2c51c2d36797d0a85395f0cd35 Thanks for Simon Charette for spotting some issues with the first draft of the patch.
2012-12-17Replaced '__' with LOOKUP_SEP in sql/query.pyAnssi Kääriäinen
Thanks to Simon Charette for report.
2012-12-16Fixed #10790 -- Refactored sql.Query.setup_joins()Anssi Kääriäinen
This is a rather large refactoring. The "lookup traversal" code was splitted out from the setup_joins. There is now names_to_path() method which does the lookup traveling, the actual work of setup_joins() is calling names_to_path() and then adding the joins found into the query. As a side effect it was possible to remove the "process_extra" functionality used by genric relations. This never worked for left joins. Now the extra restriction is appended directly to the join condition instead of the where clause. To generate the extra condition we need to have the join field available in the compiler. This has the side-effect that we need more ugly code in Query.__getstate__ and __setstate__ as Field objects aren't pickleable. The join trimming code got a big change - now we trim all direct joins and never trim reverse joins. This also fixes the problem in #10790 which was join trimming in null filter cases.
2012-12-16Fixed #18816 -- Removed "trim" argument from add_filter()Anssi Kääriäinen
The trim argument was used by split_exclude() only to trim the last join from the given lookup. It is cleaner to just trim the last part from the lookup in split_exclude() directly so that there is no need to burden add_filter() with the logic needed for only split_exclude().
2012-11-28Fixed #14694 -- Made ``defer()`` work with reverse relationsTai Lee
Reverse o2o fields are now usable with defer.
2012-11-24Updated stale docstring of setup_joinsAnssi Kääriäinen
2012-11-23Fixed #18375 -- Removed dict-ordering dependency for F-expressionsAnssi Kääriäinen
F() expressions reuse joins like any lookup in a .filter() call - reuse multijoins generated in the same .filter() call else generate new joins. Also, lookups can now reuse joins generated by F(). This change is backwards incompatible, but it is required to prevent dict randomization from generating different queries depending on .filter() kwarg ordering. The new way is also more consistent in how joins are reused.
2012-11-15Fixed #13781 -- Improved select_related in inheritance situationsAnssi Kääriäinen
The select_related code got confused when it needed to travel a reverse relation to a model which had different parent than the originally travelled relation. Thanks to Trac aliases shauncutts for report and ungenio for original patch (committed patch is somewhat modified version of that).
2012-11-15Fixed #19058 -- Fixed Oracle GIS crashAnssi Kääriäinen
The problem is the same as in #10888 which was reintroduced when bulk_insert was added. Thanks to Jani Tiainen for report, patch and also testing the final patch on Oracle GIS.
2012-11-13Removed use of SortedDict for query.alias_refcountAnssi Kääriäinen
This will have a smallish impact on performance. Refs #19276.
2012-11-08Fixed #17144 -- MySQL again groups by PK onlyAnssi Kääriäinen
Thanks to Christian Oudard for the report and tests.
2012-10-31Removed dupe_avoidance from sql/query and sql/compiler.pyAnssi Kääriäinen
The dupe avoidance logic was removed as it doesn't seem to do anything, it is complicated, and it has nearly zero documentation. The removal of dupe_avoidance allowed for refactoring of both the implementation and signature of Query.join(). This refactoring cascades again to some other parts. The most significant of them is the changes in qs.combine(), and compiler.select_related_descent().
2012-10-27Fixed #19190 -- Refactored Query select clause attributesAnssi Kääriäinen
The Query.select and Query.select_fields were collapsed into one list because the attributes had to be always in sync. Now that they are in one attribute it is impossible to edit them out of sync. Similar collapse was done for Query.related_select_cols and Query.related_select_fields.
2012-10-26Fixed #15040 - Boolean fields return 0 and 1 when loaded through select_relatedLuke Plant
Thanks to homm for the report and ramiro for the patch.
2012-10-25Fixed regression caused by #19102Anssi Kääriäinen
2012-10-25Added docstring to DeleteQuery.delete_qs()Anssi Kääriäinen
2012-10-25Fixed #19102 -- Fixed fast-path delete for modified SELECT clause casesAnssi Kääriäinen
There was a bug introduced in #18676 which caused fast-path deletes implemented as "DELETE WHERE pk IN <subquery>" to fail if the SELECT clause contained additional stuff (for example extra() and annotate()). Thanks to Trac alias pressureman for spotting this regression.
2012-10-10Fixed #19096 -- Made can_return_id_from_insert more extendableMichael Manfre
RETURNING is an extension of the SQL standard, which is not implemented the same by all databases. Allow DatabaseOperations.return_insert_id to return a None to allow for other 3rd party backends with a different implementation.
2012-10-08Fixed #19087 -- Ensured query's base table is never LOUTER joinedAnssi Kääriäinen
This fixes a regression created by join promotion logic refactoring: 01b9c3d5193fe61b82ae8b26242a13fdec22f211 Thanks to Ivan Virabyan for the report.
2012-09-30Avoided storing ExpressionNodes in dictsAnssi Kääriäinen
2012-09-28Fixed #18676 -- Allow fast-path deletion of objectsAnssi Kääriäinen
Objects can be fast-path deleted if there are no signals, and there are no further cascades. If fast-path is taken, the objects do not need to be loaded into memory before deletion. Thanks to Jeremy Dunck, Simon Charette and Alex Gaynor for reviewing the patch.
2012-09-16Fixed #17485 regression -- only + select_related interactionAnssi Kääriäinen
When doing deeper than one level select_related() + only queries(), the code introduced in b6c356b7bb97f3d6d4831b31e67868313bbbc090 errored incorrectly. Thanks to mrmachine for report & test case.
2012-09-08Internal refactoring; moving LOOKUP_SEP up one level.Malcolm Tredinnick
In an ideal world, nothing except django.db.models.query should have to import stuff from django.models.sql.*. A few things were needing to get hold of sql.constants.LOOKUP_SEP, so this commit moves it up to django.db.models.constants.LOOKUP_SEP. There are still a couple of places (admin) poking into sql.* to get QUERY_TERMS, which is unfortunate, but a slightly different issue and harder to adjust.
2012-09-07Cleaned up some small bits of the ORM, including removing an import *.Alex Gaynor
2012-08-26Code comment fix.Mitar
2012-08-25Fixed #16715 -- Fixed join promotion logic for nested nullable FKsAnssi Kääriäinen
The joins for nested nullable foreign keys were often created as INNER when they should have been OUTER joins. The reason was that only the first join in the chain was promoted correctly. There were also issues with select_related etc. The basic structure for this problem was: A -[nullable]-> B -[nonnull]-> C And the basic problem was that the A->B join was correctly LOUTER, the B->C join not. The major change taken in this patch is that now if we promote a join A->B, we will automatically promote joins B->X for all X in the query. Also, we now make sure there aren't ever join chains like: a LOUTER b INNER c If the a -> b needs to be LOUTER, then the INNER at the end of the chain will cancel the LOUTER join and we have a broken query. Sebastian reported this problem and did also major portions of the patch.
2012-08-21Fixed #17886 -- Fixed join promotion in ORed nullable queriesAnssi Kääriäinen
The ORM generated a query with INNER JOIN instead of LEFT OUTER JOIN in a somewhat complicated case. The main issue was that there was a chain of nullable FK -> non-nullble FK, and the join promotion logic didn't see the need to promote the non-nullable FK even if the previous nullable FK was already promoted to LOUTER JOIN. This resulted in a query like a LOUTER b INNER c, which incorrectly prunes results.
2012-08-14[py3] Removed unnecessary calls to .keys()Aymeric Augustin
when computing the length of a dictionary. This fails on Python 3.
2012-08-12Fixed #18731 -- Cleaned up split_exclude's use of can_reuseAnssi Kääriäinen
The outer query's set of reusable joins (can_reuse) was passed to the inner query's add_filter call. This was incorrect.
2012-08-08remove a bunch of unnescesarry iterkeys() callsAlex Gaynor
2012-08-07[py3] Ported django.utils.encoding.Aymeric Augustin
* Renamed smart_unicode to smart_text (but kept the old name under Python 2 for backwards compatibility). * Renamed smart_str to smart_bytes. * Re-introduced smart_str as an alias for smart_text under Python 3 and smart_bytes under Python 2 (which is backwards compatible). Thus smart_str always returns a str objects. * Used the new smart_str in a few places where both Python 2 and 3 want a str.
2012-08-07[py3] Fixed access to dict keys/values/items.Aymeric Augustin
2012-07-22[py3] Added Python 3 compatibility for xrange.Aymeric Augustin
2012-07-22[py3] Switched to Python 3-compatible imports.Aymeric Augustin
xrange/range will be dealt with in a separate commit due to the huge number of changes.
2012-07-17Switched to use a more idiomatic construct.Alex Gaynor
2012-07-17Fixed #17497 -- Corrected FieldError message in add_fields()Anssi Kääriäinen
The erroneous message was user visible in values_list() calls. Thanks to ojii for report and review, and to antoviaque for the patch.
2012-07-16Fixed #18056 - Cleared aggregations on DateQuery.add_date_selectNuno Maltez
Cleared aggregations on add_date_select method so only distinct dates are returned when dealing with a QuerySet that contained aggregations. That would cause the query set to return repeated dates because it would look for distinct (date kind, aggregation) pairs.
2012-07-03Fixed comment wording in sql/where.pyAnssi Kääriäinen
Thanks to Simon Charette for noticing this.
2012-07-01Fixed a regression introduced in where.as_sql() refactorAnssi Kääriäinen
At least Oracle needs parentheses in negated where conditions, even if there is only single condition negated. Fixed this by reverting to old logic in that part of as_sql() and adding a comment about this. I did not investigate why the parentheses are needed. The original offending commit was bd283aa844b04651b7c8b4e85f48c6dced1678f0.
2012-07-01Refactored the empty/full result logic in WhereNode.as_sql()Anssi Kääriäinen
Made sure the WhereNode.as_sql() handles various EmptyResultSet and FullResultSet conditions correctly. Also, got rid of the FullResultSet exception class. It is now represented by '', [] return value in the as_sql() methods.
2012-06-26Fixed #17485 -- Made defer work with select_relatedAnssi Kääriäinen
This commit tackles a couple of issues. First, in certain cases there were some mixups if field.attname or field.name should be deferred. Field.attname is now always used. Another issue tackled is a case where field is both deferred by .only(), and selected by select_related. This case is now an error. A lot of thanks to koniiiik (Michal Petrucha) for the patch, and to Andrei Antoukh for review.
2012-05-24Fixed qs.order_by() join promotion for already existing joinsAnssi Kääriäinen
When order_by causes new joins to be added to the query, the joins must be LEFT OUTER joins for nullable relations, otherwise the order_by could cause the results to be altered. This commit fixes the logic to only promote new joins, previously all joins in the order_by lookup path were promoted. Thanks to Bruno Desthuilliers for spotting this corner case.
2012-05-22Replaced 'next' testing by collections.Iterator testing.Claude Paroz
The new construct is also Python 3 compatible (where 'next' has been renamed to '__next__').