Skip to content

Commit

Permalink
Repeat calls to SolrQuerySet.only should replace, not extend field limit
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Mar 20, 2019
1 parent 159440e commit 1de9194
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
CHANGELOG
=========


0.2
---

* Subquent calls to SolrQuerySet.only() now *replaces* field limit options
rather than adding to them.

0.1.1
-----

Expand Down
6 changes: 4 additions & 2 deletions parasolr/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,16 @@ def query(self, **kwargs):

def only(self, *args, **kwargs):
"""Use field limit option to return only the specified fields.
Optionally provide aliases for them in the return. Example::
Optionally provide aliases for them in the return. Subsequent
calls will *replace* any previous field limits. Example::
queryset.only('title', 'author', 'date')
queryset.only('title:title_t', 'date:pubyear_i')
"""
qs_copy = self._clone()
qs_copy.field_list.extend(args)
# *replace* any existing field list with the current values
qs_copy.field_list = list(args)
for key, value in kwargs.items():
qs_copy.field_list.append('%s:%s' % (key, value))

Expand Down
6 changes: 3 additions & 3 deletions parasolr/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ def test_only(self):
# original field list unchanged
assert not sqs.field_list

# chaining is equivalent
fields_sqs = sqs.only('title').only('author').only('date')
# chaining is not equivalent, but *replaces*
fields_sqs = sqs.only('title').only('author')
# field list refined
assert fields_sqs.field_list == only_fields
assert fields_sqs.field_list == ['author']
# original field list unchanged
assert not sqs.field_list

Expand Down

0 comments on commit 1de9194

Please sign in to comment.