summaryrefslogtreecommitdiff
path: root/django/db/models/sql
AgeCommit message (Collapse)Author
2013-02-20[1.5.x] Fixed #19672 -- Error in negated Q() filteringAnssi Kääriäinen
There was a variable overwrite error in negated join filtering. This happened when add_filter() was adding the IS NULL condition to the WHERE clause. This is not a backport from master as there have been some other refactorings which made this patch irrelevant. The patch is from Ian Kelly.
2012-12-21[1.5.x] Refactored proxy model skipping in get_default_columns()Anssi Kääriäinen
The refactoring allows custom subclasses to use different default columns than the base model.
2012-11-28[1.5.x] Fixed #14694 -- Made ``defer()`` work with reverse relationsTai Lee
Reverse o2o fields are now usable with defer. Backpatch of [6ebf115206289bce8f3d86318871faac13d6e835]
2012-11-23[1.5.x] Fixed #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. Backpatch of 90b86291d022a09031d1df397d7aaebc30e435f7
2012-11-15[1.5.x] Fixed #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. Backpatch of 92d7f541da8b59520c833b19fbba52d3ecef2428
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-08[1.5.x] Fixed #17144 -- MySQL again groups by PK onlyAnssi Kääriäinen
Thanks to Christian Oudard for the report and tests. Backpatch of [cafb266954e21dd55ddfa90597bcf02c022bcb7d] Conflicts: django/db/models/sql/compiler.py
2012-10-26[1.5.x] Fixed #15040 - Boolean fields return 0 and 1 when loaded through ↵Luke Plant
select_related Thanks to homm for the report and ramiro for the patch. Backport of f3a2bcdee906f7ca1434b6275fdc09b3a454cf46 from master
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__').
2012-05-22Fixed #18304 -- Optimized save() when update_can_self_select=FalseAnssi Kääriäinen
Databases with update_can_self_select = False (MySQL for example) generated non-necessary queries when saving a multitable inherited model, and when the save resulted in update.
2012-05-10Replaced foo.next() by next(foo).Claude Paroz
This new syntax for next() has been introduced in Python 2.6 and is compatible with Python 3.
2012-05-09Fix proxy model Query.remove_inherited_models()Anssi Kääriäinen
Fixed #18248 -- proxy models were added to included_inherited_models in sql.query.Query. The variable is meant to be used for multitable inheritance only. This mistake caused problems in situations where proxy model's query was reused.
2012-05-07Imported zip from future_builtins instead of itertools.izip.Claude Paroz
In Python 3, itertools.izip is not available any more (behaviour integrated in standard zip).
2012-04-29Switch a datastructure internal to the ORM to be a set, instead of a dictionary.Alex Gaynor
2012-04-29Fixed #17644 -- Changed Query.alias_map to use namedtuplesAdrian Holovaty
This makes the code easier to understand and may even have a benefit in memory usage (namedtuples instead of dicts). Thanks, lrekucki and akaariai
2012-04-29Fixed #18013 -- Use the new 'as' syntax for exceptions.Claude Paroz
Thanks Clueless for the initial patch. Note that unittest has been purposely left out (external package only used by Python 2.6).
2012-04-29Removed unused variable from sql/query.pyAnssi Kääriäinen
2012-04-29Prevent Oracle from changing field.null to TrueAnssi Kääriäinen
Fixed #17957 -- when using Oracle and character fields, the fields were set null = True to ease the handling of empty strings. This caused problems when using multiple databases from different vendors, or when the character field happened to be also a primary key. The handling was changed so that NOT NULL is not emitted on Oracle even if field.null = False, and field.null is not touched otherwise. Thanks to bhuztez for the report, ramiro for triaging & comments, ikelly for the patch and alex for reviewing.
2012-04-29Simplified QuerySet field.null handlingAnssi Kääriäinen
QuerySet had previously some complex logic for dealing with nullable fields in negated add_filter() calls. It seems the logic is leftover from a time where the WhereNode wasn't as intelligent in handling field__in=[] conditions. Thanks to aaugustin for comments on the patch.
2012-04-09Fixed #17877 -- Ensured that extra WHERE clauses get correctly ANDed when ↵Julien Phalip
they contain OR operations. Thanks to Marek Brzóska for the report, to eleather for the test case and to Adrien Lemaire for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17880 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-04-08Fixed #18014 -- Removed rev_join_map from sql/query.py.Anssi Kääriäinen
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17878 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-03-22Used SortedDict instead of dict to avoid random errors that may occur when ↵Aymeric Augustin
dict randomization is enabled in Python. Refs #17758. Thanks Łukasz Rekucki. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17777 bcc190cf-cafb-0310-a4f2-bffc1f526a37