summaryrefslogtreecommitdiff
path: root/django/db/models/sql
AgeCommit message (Collapse)Author
2013-08-20Fixed #14056 -- Made sure LEFT JOIN aren't trimmed in ORDER BYAnssi Kääriäinen
If LEFT JOINs are required for correct results, then trimming the join can lead to incorrect results. Consider case: TBL A: ID | TBL B: ID A_ID 1 1 1 2 Now A.order_by('b__a') did use a join to B, and B's a_id column. This was seen to contain the same value as A's id, and so the join was trimmed. But this wasn't correct as the join is LEFT JOIN, and for row A.id = 2 the B.a_id column is NULL.
2013-08-19Fixed #11881 -- removed junk from aggregation subqueriesAnssi Kääriäinen
There were clauses that weren't needed in the subqueries. These were ORDER BY, SELECT FOR UPDATE and related selections.
2013-08-19Fixed #12886 -- aggregation over sliced querysetAnssi Kääriäinen
2013-08-13Fixed #20874 -- bump_prefix() in nested subqueriesAnssi Kääriäinen
Also made some cleanup to build_filter() code by introducing submethods solve_lookup_type() and prepare_lookup_value().
2013-08-07Fixed #17424 -- annotate() + exclude() bugAnssi Kääriäinen
The bug was already fixed by 01b9c3d5193fe61b82ae8b26242a13fdec22f211, so only tests added. At the same time promote_joins()'s uncoditional flag is gone, it isn't needed for anything any more.
2013-08-04Deprecated SortedDict (replaced with collections.OrderedDict)Curtis Maloney
Thanks Loic Bistuer for the review.
2013-07-31Fixed #15624 -- Made sure aggregations are present in SELECTFlorian Hahn
2013-07-31Added field.attname to Options.name_mapAnssi Kääriäinen
The change also removed allow_explicit_fk from sql/query.py.
2013-07-31Fixed #20348 -- Consistently handle Promise objects in model fields.Tai Lee
All Promise objects were passed to force_text() deep in ORM query code. Not only does this make it difficult or impossible for developers to prevent or alter this behaviour, but it is also wrong for non-text fields. This commit changes `Field.get_prep_value()` from a no-op to one that resolved Promise objects. All subclasses now call super() method first to ensure that they have a real value to work with.
2013-07-29Removed most of absolute_import importsClaude Paroz
Should be unneeded with Python 2.7 and up. Added some unicode_literals along the way.
2013-07-23Fixed #20782 -- qs.values().aggregate() failureAnssi Kääriäinen
In the combination of .values().aggregate() the aggregate_select_mask didn't include the aggregates added. This resulted in bogus query. Thanks to Trac alias debanshuk for report.
2013-07-14Fixed #20746 -- Removed Python 2.6 specific code/docsTim Graham
2013-07-09Fixed #17339 -- Factor out has_result into database backend.Tim Graham
Thanks jonash.
2013-07-08A large number of stylistic cleanups across django/db/Alex Gaynor
2013-06-18Fixed #14930 -- values_list() failure on qs ordered by extra columnFlorian Hahn
Thanks lsaffre for the report and simon29, vicould, and Florian Hahn for the patch. Some changes done by committer.
2013-06-16Fixed #20583 -- ORM always uses setup_joins() for join generationAnssi Kääriäinen
There were a couple of places which used Query.join() directly. By using setup_joins() in these places the code is more DRY, and in addition there is no need to directly call field.get_joining_columns() unless the field is the given join_field from get_path_info(). This makes it easier to make sure a ForeignObject subclass generates joins correctly in all cases.
2013-06-14Fixed #20528 -- regression in select_related join promotionAnssi Kääriäinen
The join used by select_related was incorrectly INNER when the query had an ORed filter for nullable join that was trimmed away. Fixed this by forcing the join type to LOUTER even when a join was trimmed away in ORed queries.
2013-06-06Fixed #20564 -- Generic relations exclude() regressionAnssi Kääriäinen
The patch for #19385 caused a regression in certain generic relations .exclude() filters if a subquery was needed. The fix contains a refactoring to how Query.split_exclude() and Query.trim_start() interact. Thanks to Trac alias nferrari for the report.
2013-05-30Fixed #16436 -- defer + annotate + select_related crashTai Lee
Correctly calculate the ``aggregate_start`` offset from loaded fields, if any are deferred, instead of ``self.query.select`` which includes all fields on the model. Also made some PEP 8 fixes.
2013-05-27Fixed #20507 -- SubqueryConstraint alias relabelingAnssi Kääriäinen
The SubqueryConstraint defined relabeled_clone(), but that was never called. Instead there is now clone() and relabel_aliases() methods for SubqueryConstraint. A related problem was that SubqueryConstraint didn't correctly use quote_name_unless_alias() of the outer query. This resulted in failures when running under PostgreSQL.
2013-05-26Replaced `and...or...` constructs with PEP 308 conditional expressions.Ramiro Morales
2013-05-20Fixed qs.values() regression when used in subqueryAnssi Kääriäinen
2013-05-19Fixed #11442 -- Postgresql backend casts all inet types to textErik Romijn
2013-05-17Replaced an antiquated pattern.Aymeric Augustin
Thanks Lennart Regebro for pointing it out.
2013-05-15Fixed #20413 - Respect Query.get_meta()Mike Fogel
2013-05-08Fixed test failures on MySQL.Aymeric Augustin
Some tests failed when the time zone definitions were loaded in MySQL and pytz wasn't installed. This setup isn't supported.
2013-04-08Fixed #14019 -- Initialize `SQLInsertCompiler.return_id` attribute.Tobias McNulty
2013-03-26Fixed #20091 -- Oracle null promotion for empty stringsAnssi Kääriäinen
2013-03-24Fixed Oracle specific failures in multicolumn joinsAnssi Kääriäinen
Refs #19385
2013-03-24Fixed #19385 again, now with real code changesAnssi Kääriäinen
The commit of 266de5f9ae9e9f2fbfaec3b7e4b5fb9941967801 included only tests, this time also code changes included...
2013-03-22Fixed #20094 - Be more careful when checking for IteratorMarc Tamlyn
Python 2.6 has some different behaviour when checking isinstance(foo, collections.Iterator).
2013-03-21Removed unused importAnssi Kääriäinen
2013-03-17Fixed #19635 -- Made fields pickleableAnssi Kääriäinen
2013-03-13Refactored qs.add_q() and utils/tree.pyAnssi Kääriäinen
The sql/query.py add_q method did a lot of where/having tree hacking to get complex queries to work correctly. The logic was refactored so that it should be simpler to understand. The new logic should also produce leaner WHERE conditions. The changes cascade somewhat, as some other parts of Django (like add_filter() and WhereNode) expect boolean trees in certain format or they fail to work. So to fix the add_q() one must fix utils/tree.py, some things in add_filter(), WhereNode and so on. This commit also fixed add_filter to see negate clauses up the path. A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to .filter(~Q(reversefk__in=a_list)). The reason for this is that only the immediate parent negate clauses were seen by add_filter, and thus a tree like AND: (NOT AND: (AND: condition)) will not be handled correctly, as there is one intermediary AND node in the tree. The example tree is generated by .exclude(~Q(reversefk__in=a_list)). Still, aggregation lost connectors in OR cases, and F() objects and aggregates in same filter clause caused GROUP BY problems on some databases. Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2013-03-12Fixed #19964 -- Removed relabel_aliases from some structsAnssi Kääriäinen
Before there was need to have both .relabel_aliases() and .clone() for many structs. Now there is only relabeled_clone() for those structs where alias is the only mutable attribute.
2013-02-28Fixed #19929 -- Improved error when MySQL doesn't have TZ definitions.Aymeric Augustin
Thanks tomas_00 for the report.
2013-02-28Fixed #12823 -- Was already fixed in master, tests addedAnssi Kääriäinen
Also added a little improvement to sql/query.py to get rid of non-necessary IS NOT NULL check.
2013-02-27Fixed #19861 -- Transaction ._dirty flag improvementAnssi Kääriäinen
There were a couple of errors in ._dirty flag handling: * It started as None, but was never reset to None. * The _dirty flag was sometimes used to indicate if the connection was inside transaction management, but this was not done consistently. This also meant the flag had three separate values. * The None value had a special meaning, causing for example inability to commit() on new connection unless enter/leave tx management was done. * The _dirty was tracking "connection in transaction" state, but only in managed transactions. * Some tests never reset the transaction state of the used connection. * And some additional less important changes. This commit has some potential for regressions, but as the above list shows, the current situation isn't perfect either.
2013-02-24Revert "fixes #19263" - Fails if not SQLiteHonza Kral
This reverts commit 2b76f19f2b89ac96bae2a169d71b23553c8101c7.
2013-02-23fixes #19263Marcin Biernat
2013-02-21Fixed #19870 -- Regression in select_related in inheritance casesAnssi Kääriäinen
There was a regression in case two models inherited the same parent, and one contained a foreign key to other. When select_related travelled the foreign key the other model reused the parent join made by the first model. This was likely caused by Query.join_parent_model() addition in commit 68985db48212c701a3d975636123a5d79bdc006f. Thanks to Trac alias loic84 for report & tests.
2013-02-20Cleaned up join promotion in query.combine() with ORAnssi Kääriäinen
Refs #19849
2013-02-20Removed join() promote kwargAnssi Kääriäinen
The join promote=True was over-aggressive in select_related handling. After that was removed, the only other user was query.combine(). That use case is very easy to handle locally, so there is no more need for the join(promote=True) flag. Refs #19849.
2013-02-20Refactored negated IS NULL handlingAnssi Kääriäinen
This one cleaned up add_filter() negated filter generation. As a side effect split_exclude() was cleaned up, too. Refs #19849
2013-02-19Fixed #19837 -- Refactored split_exclude() join generationAnssi Kääriäinen
The refactoring mainly concentrates on making sure the inner and outer query agree about the split position. The split position is where the multijoin happens, and thus the split position also determines the columns used in the "WHERE col1 IN (SELECT col2 from ...)" condition. This commit fixes a regression caused by #10790 and commit 69597e5bcc89aadafd1b76abf7efab30ee0b8b1a. The regression was caused by wrong cols in the split position.
2013-02-16Fixed #17260 -- Added time zone aware aggregation and lookups.Aymeric Augustin
Thanks Carl Meyer for the review. Squashed commit of the following: commit 4f290bdb60b7d8534abf4ca901bd0844612dcbda Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 21:21:30 2013 +0100 Used '0:00' instead of 'UTC' which doesn't always exist in Oracle. Thanks Ian Kelly for the suggestion. commit 01b6366f3ce67d57a58ca8f25e5be77911748638 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 13:38:43 2013 +0100 Made tzname a parameter of datetime_extract/trunc_sql. This is required to work around a bug in Oracle. commit 924a144ef8a80ba4daeeafbe9efaa826566e9d02 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 14:47:44 2013 +0100 Added support for parameters in SELECT clauses. commit b4351d2890cd1090d3ff2d203fe148937324c935 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 22:30:22 2013 +0100 Documented backwards incompatibilities in the two previous commits. commit 91ef84713c81bd455f559dacf790e586d08cacb9 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 09:42:31 2013 +0100 Used QuerySet.datetimes for the admin's date_hierarchy. commit 0d0de288a5210fa106cd4350961eb2006535cc5c Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 09:29:38 2013 +0100 Used QuerySet.datetimes in date-based generic views. commit 9c0859ff7c0b00734afe7fc15609d43d83215072 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:25 2013 +0100 Implemented QuerySet.datetimes on Oracle. commit 68ab511a4ffbd2b811bf5da174d47e4dd90f28fc Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:14 2013 +0100 Implemented QuerySet.datetimes on MySQL. commit 22d52681d347a8cdf568dc31ed032cbc61d049ef Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:42:29 2013 +0100 Implemented QuerySet.datetimes on SQLite. commit f6800fd04c93722b45f9236976389e0b2fe436f5 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:03 2013 +0100 Implemented QuerySet.datetimes on PostgreSQL. commit 0c829c23f4cf4d6804cadcc93032dd4c26b8c65e Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:41:08 2013 +0100 Added datetime-handling infrastructure in the ORM layers. commit 104d82a7778cf3f0f5d03dfa53709c26df45daad Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 10:05:55 2013 +0100 Updated null_queries tests to avoid clashing with the __second lookup. commit c01bbb32358201b3ac8cb4291ef87b7612a2b8e6 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 23:07:41 2013 +0100 Updated tests of .dates(). Replaced .dates() by .datetimes() for DateTimeFields. Replaced dates with datetimes in the expected output for DateFields. commit 50fb7a52462fecf0127b38e7f3df322aeb287c43 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:40:09 2013 +0100 Updated and added tests for QuerySet.datetimes. commit a8451a5004c437190e264667b1e6fb8acc3c1eeb Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 22:34:46 2013 +0100 Documented the new time lookups and updated the date lookups. commit 29413eab2bd1d5e004598900c0dadc0521bbf4d3 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 16:15:49 2013 +0100 Documented QuerySet.datetimes and updated QuerySet.dates.
2013-02-11Added a check in the creation of IS NULL clauses.Aymeric Augustin
value_annotation isn't very well defined. Before this change, setting it to datetime.datetime could silently reverse the behavior of isnull lookups. This commit doesn't have any consequences on the current code. It's just a safeguard for future ORM hackers.
2013-02-10Made Query.clear_ordering force_empty arg mandatoryAnssi Kääriäinen
Previously it was possible to call clear_ordering without the force_empty argument. The result was that the query was still ordered by model's meta ordering if that was defined. By making the arg mandatory it will be easier to spot possible errors caused by assuming clear_ordering will remove all ordering. Thanks to Dylan Klomparens for the suggestion. Refs #19720.
2013-01-08Fixed #16759 -- Remove use of __deepcopy__ in qs.clone()Anssi Kääriäinen
The original problem was that queryset cloning was really expensive when filtering with F() clauses. The __deepcopy__ went too deep copying _meta attributes of the models used. To fix this the use of __deepcopy__ in qs cloning was removed. This commit results in some speed improvements across the djangobench benchmark suite. Most query_* tests are 20-30% faster, save() is 50% faster and finally complex filtering situations can see 2x to order of magnitude improvments. Thanks to Suor, Alex and lrekucki for valuable feedback.
2013-01-06Fixed #19173 -- Made EmptyQuerySet a marker class onlyAnssi Kääriäinen
The guarantee that no queries will be made when accessing results is done by new EmptyWhere class which is used for query.where and having. Thanks to Simon Charette for reviewing and valuable suggestions.