Commit Graph

136 Commits

Author SHA1 Message Date
Anssi Kääriäinen d407164c04 Fixed #18854 -- Join promotion in disjunction cases
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-20 21:45:15 +02:00
Anssi Kääriäinen 3dcd435a0e Fixed #19500 -- Solved a regression in join reuse
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
68847135bc

Thanks for Simon Charette for spotting some issues with the first draft
of the patch.
2012-12-20 21:27:00 +02:00
Anssi Kääriäinen 69597e5bcc Fixed #10790 -- Refactored sql.Query.setup_joins()
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-16 17:23:26 +02:00
Anssi Kääriäinen 088d3bc2f8 Fixed #19462 -- Made assertQuerysetEqual detect undefined ordering
If there are more than one values to compare against and the qs isn't
ordered then assertQuerysetEqual will raise a ValueError.
2012-12-13 13:33:11 +02:00
Florian Apolloner 7e97f4f510 Fixed an order dependant test failure. 2012-12-11 16:25:47 +01:00
Anssi Kääriäinen 68847135bc Removed dupe_avoidance from sql/query and sql/compiler.py
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-31 08:19:44 +02:00
Jan Bednařík b87e2f46c8 Fixed #19151 -- Added missing methods to EmptyQuerySet.
Added values() and values_list() methods to EmptyQuerySet.
2012-10-21 00:19:38 +02:00
Alex Gaynor 335a9f9cf1 Removed many uses of bare "except:", which were either going to a) silence real issues, or b) were impossible to hit. 2012-09-07 15:08:07 -04:00
Anssi Kääriäinen a193372753 Fixed #17886 -- Fixed join promotion in ORed nullable queries
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-21 21:23:57 +03:00
Alex Gaynor 54afdbf378 Fixed usage of several deprecated aliases in unittest. 2012-08-15 01:38:04 -07:00
Anssi Kääriäinen 5b27e6f64b [py3] Fixed comparison of list and range()
A test compared list directly against a range(). This is py3
incompatible. Fixed by using list(range()).
2012-08-14 15:28:55 +03:00
Anssi Kääriäinen 8fe03865f7 [py3] Fixed invalid use of dict.items()
An ordering test had two problems related to dict.items() usage:
  - It assumed the order of the dict was non-randomized
  - It indexed to the dict.items() which is py3 incompatible.

I fixed the test by using dict['rank'] directly, where rank is the
column tested on the values queryset.
2012-08-14 15:24:43 +03:00
Aymeric Augustin d4a0b27838 [py3] Refactored __unicode__ to __str__.
* Renamed the __unicode__ methods
* Applied the python_2_unicode_compatible decorator
* Removed the StrAndUnicode mix-in that is superseded by
  python_2_unicode_compatible
* Kept the __unicode__ methods in classes that specifically
  test it under Python 2
2012-08-12 14:44:40 +02:00
Aymeric Augustin bdca5ea345 [py3] Replaced unicode/str by six.text_type/bytes. 2012-07-22 09:29:54 +02:00
Anssi Kääriäinen 29132ebdef Fixed #17788 -- Added batch_size argument to qs.bulk_create()
The qs.bulk_create() method did not work with large batches together
with SQLite3. This commit adds a way to split the bulk into smaller
batches. The default batch size is unlimited except for SQLite3 where
the batch size is limited to 999 SQL parameters per batch.

Thanks to everybody who participated in the discussions at Trac.
2012-07-17 15:24:41 +03:00
Anssi Kääriäinen e74787391e Fixed a regression introduced in where.as_sql() refactor
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 bd283aa844.
2012-07-01 22:52:35 +03:00
Anssi Kääriäinen bd283aa844 Refactored the empty/full result logic in WhereNode.as_sql()
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-07-01 17:21:34 +03:00
Claude Paroz 4a103086d5 Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.
Thanks Vinay Sajip for the support of his django3 branch and
Jannis Leidel for the review.
2012-06-07 18:08:47 +02:00
Anssi Kääriäinen 323b414441 Added tests for nested exclude/negate queries 2012-05-25 14:10:45 +03:00
Anssi Kääriäinen 8c72aa2379 Fixed qs.order_by() join promotion for already existing joins
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-24 18:42:06 +03:00
Claude Paroz 169b1a404c Replaced foo.next() by next(foo).
This new syntax for next() has been introduced in Python 2.6 and is
compatible with Python 3.
2012-05-10 20:15:49 +02:00
Anssi Kääriäinen c2e1ecb4b1 Fix proxy model Query.remove_inherited_models()
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-09 20:33:31 +03:00
Anssi Kääriäinen 584e2c0337 Prevent Oracle from changing field.null to True
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-29 19:25:46 +03:00
Anssi Kääriäinen 5aa51fa999 Simplified QuerySet field.null handling
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-29 16:27:25 +03:00
Julien Phalip c93933441e Fixed #17429 -- Ensured that `Meta.ordering=None` works the same if it were an empty list. Thanks to self[at]dicos[dot]ru for the report and to bigkevmcd for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17334 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-01-03 09:06:19 +00:00
Ramiro Morales 287565779d Added support for modifying the effect of ``DISTINCT`` clauses so they
only consider some fields (PostgreSQL only).

For this, the ``distinct()`` QuerySet method now accepts an optional
list of model fields names and generates ``DISTINCT ON`` clauses on
these cases. Thanks Jeffrey Gelens and Anssi Kääriäinen for their work.

Fixes #6422.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 20:42:40 +00:00
Adrian Holovaty e31c43a360 Optimized an optimise
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17227 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-17 17:38:08 +00:00
Adrian Holovaty 20c8aa2a20 Fixed various dodgy behaviours
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17226 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-17 17:37:24 +00:00
Ramiro Morales 5f2be4ecbb Fixed #17056 -- Tweaked insert SQL clause generation so a corner case doesn't fail with Oracle.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16997 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-10-16 20:06:59 +00:00
Alex Gaynor 8c0eefd066 Convert the remainder of the relative imports in the tests to be absolute imports.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16981 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-10-13 21:34:56 +00:00
Jannis Leidel 2eadc418af Fixed doc references to `django.db.models.query.QuerySet` and converted some tabs that were introduced in r16699 to spaces.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16915 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-09-30 10:28:39 +00:00
Russell Keith-Magee fcee0c1b66 Fixed #16809 -- Forced MySQL to behave like a database. This avoids a problem where queries that do IS NONE checks can return the wrong result the first time they are executed if there is a recently inserted row. Thanks to James Pyrich for the debug work and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16785 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-09-10 18:58:30 +00:00
Russell Keith-Magee 228654d17f Added two pointless query repeats to work around a known issue with MySQL that was causing failures in our test suite.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16753 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-09-09 23:02:33 +00:00
Malcolm Tredinnick a86dde20f0 Fixed a broken test from r16656.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16667 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-08-23 06:28:45 +00:00
Malcolm Tredinnick 2e56066a5b Fixed an isnull=False filtering edge-case. Fixes #15316.
The bulk of this patch is due to some fine analysis from Aleksandra
Sendecka.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16656 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-08-23 03:38:42 +00:00
Russell Keith-Magee 3afe409d0e Fixed #14876 -- Ensure that join promotion works correctly when there are nullable related fields. Thanks to simonpercivall for the report, oinopion and Aleksandra Sendecka for the original patch, and to Malcolm for helping me wrestle the edge cases to the ground.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16648 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-08-22 07:40:12 +00:00
Ramiro Morales 326949e444 Fixed #14503 -- Unified multiple implementations of test cases assert* methods that verify a given exception is raised by a callable throughout the Django test suite.
Replaced them with a new assertRaisesMessage method of a new SimpleTestCase, a lightweight subclass of unittest.TestCase. Both are also available for usage in user tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16610 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-08-13 00:42:08 +00:00
Jannis Leidel c77372cad0 Fixed #14729 -- RawQuerySet.__repr__ fails when params passed as list. Thanks, intgr for ticket and accuser for patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16088 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-04-22 18:17:26 +00:00
Adrian Holovaty 4e25bc71b1 Fixed #15609 -- Fixed some 'raise' statements to use the newer style syntax. Thanks, DaNmarner
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15811 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-03-14 23:00:03 +00:00
Ian Kelly 8b22f7cf78 Fixed field names that were preventing the tests from running in Oracle.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15774 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-03-08 19:26:32 +00:00
Russell Keith-Magee afd040d4d3 Updated test assertions that have been deprecated by the move to unittest2. In summary, this means:
assert_ -> assertTrue
 assertEquals -> assertEqual
 failUnless -> assertTrue

For full details, see http://www.voidspace.org.uk/python/articles/unittest2.shtml#deprecations

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15728 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-03-03 15:04:39 +00:00
Russell Keith-Magee b7c41c1fbb Fixed #12252 -- Ensure that queryset unions are commutative. Thanks to benreynwar for the report, and draft patch, and to Karen and Ramiro for the review eyeballs and patch updates.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15726 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-03-03 13:51:54 +00:00
Carl Meyer 227c5e80db Fixed #11319 - Added lookup support for ForeignKey.to_field. Also reverted no-longer-needed model formsets workaround for lack of such support from r10756. Thanks Russell and Alex for review.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15303 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-01-25 03:14:28 +00:00
Russell Keith-Magee 5502fa5980 Refs #14661 -- Corrected (well... hacked around) a test failure under MySQL/MyISAM with the queries regression test.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15238 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-01-18 16:42:24 +00:00
Ramiro Morales a360240c56 Fixed a couple of tests migrated to unit tests in r14279 so they actually and correctly exercise the functionality under test.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14981 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-12-18 23:03:23 +00:00
Alex Gaynor 678f626c24 Fixed a suite of errors in the ORM -- a) fixed calling values_list().values_list() and changing whether the results are flat, b) fixed an issue with fields on the left-hand side of what becomes the HAVING clause not being included in the GROUP BY clause, and c) fixed a bug with fields from values() calls not being included in the GROUP BY clause. This fixed the recent test failures under postgresql.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14715 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-26 14:24:08 +00:00
Alex Gaynor 8da8d6c586 Added a test for using an `__in` lookup with a ValueListQueryset from a none() call. Refs #14622.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14568 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-16 02:33:51 +00:00
Ramiro Morales cfbba28c39 Fixed errors introduced in r14279 when running Django tests under Python < 2.6.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14287 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-19 17:27:38 +00:00
Ramiro Morales bdaaac1254 Converted queries tests from doctests to unittests.
Thanks Russell and Alex for reviews and suggestions.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14279 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-19 04:07:22 +00:00
Ramiro Morales e1182306fd Fixed a small typo introduced in r14139.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14272 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-19 00:14:41 +00:00