File tree Expand file tree Collapse file tree 4 files changed +12
-7
lines changed Expand file tree Collapse file tree 4 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ Changelog
12
12
a backwards incompatible change for custom aggregations that redefine that
13
13
method.
14
14
* ``DocType.update `` now supports ``refresh `` kwarg
15
+ * ``DslBase._clone `` now produces a shallow copy, this means that modifying an
16
+ existing query can have effects on existing ``Search `` objects.
15
17
16
18
6.1.0 (2018-01-09)
17
19
------------------
Original file line number Diff line number Diff line change @@ -23,9 +23,10 @@ The ``Search`` object represents the entire search request:
23
23
24
24
The API is designed to be chainable. With the exception of the
25
25
aggregations functionality this means that the ``Search `` object is immutable -
26
- all changes to the object will result in a copy being created which contains
27
- the changes. This means you can safely pass the ``Search `` object to foreign
28
- code without fear of it modifying your objects.
26
+ all changes to the object will result in a shallow copy being created which
27
+ contains the changes. This means you can safely pass the ``Search `` object to
28
+ foreign code without fear of it modifying your objects as long as it sticks to
29
+ the ``Search `` object APIs.
29
30
30
31
You can pass an instance of the low-level `elasticsearch client <https://elasticsearch-py.readthedocs.io/ >`_ when
31
32
instantiating the ``Search `` object:
Original file line number Diff line number Diff line change 1
1
from __future__ import unicode_literals
2
2
3
3
import collections
4
+ from copy import copy
4
5
5
6
from six import iteritems , add_metaclass
6
7
from six .moves import map
@@ -198,7 +199,7 @@ class DslBase(object):
198
199
199
200
Provides several feature:
200
201
- attribute access to the wrapped dictionary (.field instead of ['field'])
201
- - _clone method returning a deep copy of self
202
+ - _clone method returning a copy of self
202
203
- to_dict method to serialize into dict (to be sent via elasticsearch-py)
203
204
- basic logical operators (&, | and ~) using a Bool(Filter|Query) TODO:
204
205
move into a class specific for Query/Filter
@@ -330,8 +331,10 @@ def to_dict(self):
330
331
return {self .name : d }
331
332
332
333
def _clone (self ):
333
- return self ._type_shortcut (self .to_dict ())
334
-
334
+ c = self .__class__ ()
335
+ for attr in self ._params :
336
+ c ._params [attr ] = copy (self ._params [attr ])
337
+ return c
335
338
336
339
class ObjectBase (AttrDict ):
337
340
def __init__ (self , ** kwargs ):
Original file line number Diff line number Diff line change @@ -52,7 +52,6 @@ def test_query_clone():
52
52
53
53
assert bool == bool_clone
54
54
assert bool is not bool_clone
55
- assert bool .must [0 ] is not bool_clone .must [0 ]
56
55
57
56
def test_bool_converts_its_init_args_to_queries ():
58
57
q = query .Bool (must = [{"match" : {"f" : "value" }}])
You can’t perform that action at this time.
0 commit comments