summaryrefslogtreecommitdiff
path: root/django/utils/tree.py
AgeCommit message (Collapse)Author
2022-07-27Refs #32948, Refs #32946 -- Used Q.create() internally for dynamic Q() objects.Nick Pope
Node.create() which has a compatible signature with Node.__init__() takes in a single `children` argument rather than relying in unpacking *args in Q.__init__() which calls Node.__init__(). In addition, we were often needing to unpack iterables into *args and can instead pass a list direct to Node.create().
2022-07-27Refs #32948 -- Added Node.__copy__().Nick Pope
This allows the copy.copy() usage in the Q._combine() method to finish sooner, instead of having to fallback to using the __reduce_ex__(4) method. Thia also avoids having to fall into copy.copy() at in Q._combine(), when combining a Q() with another Q(). Co-authored-by: Keryn Knight <keryn@kerynknight.com>
2022-07-27Refs #32948 -- Simplified WhereNode and Node.__deepcopy__()/add().Nick Pope
We can use copy() in Node.add() instead of create() as we don't need the children to be cloned via [:] subscript in __init__().
2022-07-27Refs #32948 -- Renamed Node._new_instance() to Node.create().Nick Pope
Node._new_instance() was added in 6dd2b5468fa275d53aa60fdcaff8c28bdc5e9c25 to work around Q.__init__() having an incompatible signature with Node.__init__(). It was intended as a hook that could be overridden if subclasses needed to change the behaviour of instantiation of their specialised form of Node. In practice this doesn't ever seem to have been used for this purpose and there are very few calls to Node._new_instance() with other code, e.g. Node.__deepcopy__() calling Node and overriding __class__ as required. Rename this to Node.create() to make it a more "official" piece of private API that we can use to simplify a lot of other areas internally. The docstring and nearby comment have been reworded to read more clearly.
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2021-07-20Refs #32940 -- Removed unnecessary branch in Node.add().Keryn Knight
The "data in self.children" branch was causing data.__eq__ to be called for each entries in "self.children" which resulted in a huge slowdown during queryset construction. It's purpose was to prevent queries of the form Model.objects.filter(foo='bar').filter(foo='bar') from resulting in WHERE foo='bar' AND foo='bar' but it's not covered by the suite and has arguable performance benefits since it's not very common and SQL engines are usually very good at folding/optimizing these. See also #32632 for prior discussion around comparing data to the Node's children. Co-authored-by: Nick Pope <nick@nickpope.me.uk>
2021-07-20Refs #32940 -- Removed Node.add()'s unused squash parameter.Keryn Knight
Unused since its introduction in d3f00bd5706b35961390d3814dd7e322ead3a9a3. Co-authored-by: Nick Pope <nick@nickpope.me.uk>
2021-07-19Removed unnecessary tuple construction in Node.__eq__().Nick Pope
2021-05-13Fixed #32717 -- Fixed filtering of querysets combined with the | operator.Simon Charette
Address a long standing bug in a Where.add optimization to discard equal nodes that was surfaced by implementing equality for Lookup instances in bbf141bcdc31f1324048af9233583a523ac54c94. Thanks Shaheed Haque for the report.
2018-10-17Fixed #29838 -- Fixed crash when combining Q objects with __in lookups and ↵aspalding
lists. Regression in fc6528b25ab1834be1a478b405bf8f7ec5cf860c.
2018-09-28Refs #28909 -- Simplifed code using unpacking generalizations.Sergey Fedoseev
2018-08-08Fixed #29643 -- Fixed crash when combining Q objects with __in lookups and ↵Mariusz Felisiak
lists. Regression in fc6528b25ab1834be1a478b405bf8f7ec5cf860c.
2018-07-18Removed duplicate words in various comments.Mariusz Felisiak
2017-09-28Fixed #28629 -- Made tree.Node instances hashable.Mariusz Felisiak
Regression in 508b5debfb16843a8443ebac82c1fb91f15da687 which added Node.__eq__().
2017-09-28Simplified various __eq__() methods.Mads Jensen
2017-02-23Refs #11964 -- Made Q objects deconstructible.Ian Foote
2017-02-11Refs #27656 -- Updated django.utils docstring verbs according to PEP 257.Anton Samarchyan
2017-02-07Refs #27795 -- Removed force_text from the template layerClaude Paroz
Thanks Tim Graham for the review.
2017-01-20Refs #23919 -- Removed unneeded force_str callsClaude Paroz
2017-01-19Refs #23919 -- Removed __nonzero__() methods (for Python 2).Simon Charette
Thanks Tim for the review.
2017-01-19Refs #23919 -- Stopped inheriting from object to define new style classes.Simon Charette
2016-04-04Fixed W503 flake8 warnings.Tim Graham
2015-12-13Fixed #25875 -- Prevented UnicodeDecodeError for Q object reprClaude Paroz
Thanks Ben Kraft for the report, and Simon Charette for the review.
2015-01-19Removed legacy ORM lookup support per deprecation timeline; refs #16187.Tim Graham
2014-12-08Fixed #23968 -- Replaced list comprehension with generators and dict ↵Jon Dufresne
comprehension
2014-05-16Fixed #22531 -- Added tree.Node.__repr__ and tests for the class.Moayad Mardini
While Node class has a useful `__str__`, its `__repr__` is not that useful. Added a `__repr__` that makes use of the current `__str__`. This is especially useful since the more popular `Q` class inherits `tree.Node`. Also created new tests that cover most of `Node` class functionality.
2013-11-19Use `classmethod` as a decorator.xuxiang
2013-11-02More attacking E302 violatorsAlex Gaynor
2013-05-17Replaced an antiquated pattern.Aymeric Augustin
Thanks Lennart Regebro for pointing it out.
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.
2012-11-03Fixed #18963 -- Used a subclass-friendly patternAymeric Augustin
for Python 2 object model compatibility methods.
2012-10-10Revert "Fixed #16211 -- Added comparison and negation ops to F() expressions"Anssi Kääriäinen
This reverts commit 28abf5f0ebc9d380f25dd278d7ef4642c4504545. Conflicts: docs/releases/1.5.txt
2012-09-30Fixed #16211 -- Added comparison and negation ops to F() expressionsAnssi Kääriäinen
Work done by Walter Doekes and Trac alias knoeb. Reviewed by Simon Charette.
2012-08-08[py3] Replaced __nonzero__ by __bool__Claude Paroz
Of course, __nonzero__ alias has been kept for Python 2 compatibility.
2011-03-28Removed a bunch more Python 2.4 workarounds now that we don't support that ↵Adrian Holovaty
version. Refs #15702 -- thanks to jonash for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15927 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-17Fixed #11753 - Q objects with callables no longer explode on Python 2.4. ↵Jacob Kaplan-Moss
Thanks, Jeremy Dunck. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-16Fixed #8283 -- Fixed an edge case when adding things to the "where" tree andMalcolm Tredinnick
combining different connector types. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8413 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-04Redo the changes in [7773] in a better way.Malcolm Tredinnick
This removes some of the leaky abstraction problems (lifting WhereNode internals into the Query class) from that commit and makes it possible for extensions to WhereNode to have access to the field instances. It's also backwards-compatible with pre-[7773] code, which is also better. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7835 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27Merged the queryset-refactor branch into trunk.Malcolm Tredinnick
This is a big internal change, but mostly backwards compatible with existing code. Also adds a couple of new features. Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658 git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37