Skip to content

Commit

Permalink
Merge pull request #165 from InCadence/null-query-fix
Browse files Browse the repository at this point in the history
Null query fix
  • Loading branch information
dclemenzi committed Mar 25, 2019
2 parents ac7d3d2 + ed36bdc commit 8020938
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
32 changes: 21 additions & 11 deletions src/pyCoalesce/pyCoalesce/coalesce_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,10 @@ def search(server = None, query = None,
of dict-like or JSON objects in the form
`{"propertyName": <recordset>.<field>, "sortOrder": <sort order>}`.
A single dict-like/JSON object in the latter format will also be
accepted. For basic entity fields, such as "name" and
"dateCreated", the field name should be supplied by itself, with no
recordset.
accepted. In some circumstances (in particular, if Derby is the
default persistor), the in the case of basic entity fields, such
as "name" and "dateCreated", a field name should be supplied by
itself, with no recordset.
:param sort_order: "ASC" for ascending, or "DESC" for descending.
This argument is used only if "sort_by" is the name of a single
field (rather than a full Coalesce "sortBy" object).
Expand Down Expand Up @@ -477,20 +478,24 @@ def _case_operators(query_fragment, fragment_is_criteria = False):
# If "query" is a full query object, assign it directly as the
# query ("data"). Otherwise, construct the query object.

if "group" in query:
if query and "group" in query:
data = query

else:

data = {"pageSize": page_size, "pageNumber": page_number,
"propertyNames": return_property_names}

# If there's a query (filter object), add it. Otherwise, if a
# "template" name was supplied (necessary if there's no query and
# no recordset in "return_property_names"), add it.
if query:
data["group"] = query
elif template:
# If there's a query (filter object), add it. If there's no
# query, create an empty object to use as the value of "group".
if not query:
query = {}
data["group"] = query

# If a "template" name was supplied (necessary if there's no
## query--or a query with only coalesceEntity metadata fields--
# and no recordset in "return_property_names"), add it.
if template:
data["type"] = template

# Add any sorting parameters. We checkfor the (deprecated) earlier
Expand All @@ -502,12 +507,17 @@ def _case_operators(query_fragment, fragment_is_criteria = False):
# Check for a JSON object that needs to be decoded.

if isinstance(sort_by, basestring):

try:
sort_by = json.loads(sort_by)

# If it's a string but not decodeable, treat it as a field
# name, and construct the sort-by object. This is the only
# case in which the "sort_order" argument is used.
# case in which the "sort_order" argument is used--in the
# case of multiple sort-by fields, each entry in the
# "sort_by" argument must include a "sortOrder" value (the
# API equivalent of "sort_order") as well as a
# "propertyName" value (the sort-by field name).
except JSONDecodeError:
sort_order = sort_order.upper()
if not sort_order in SEARCH_SORT_ORDERS:
Expand Down
7 changes: 6 additions & 1 deletion src/pyCoalesce/unit_tests/tests_coalesce_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
SEARCH_PERSISTOR = config.get("Coalesce RESTful API server", "search_persistor")

# Set other constants.
TEMPLATE1_NAME = 'TestEntity1'
TEMPLATE1_XML = '<entity ' + \
'classname="test1" ' + \
'name="TestEntity1" ' + \
'name="' + TEMPLATE1_NAME + '" ' + \
'source="pyCoalesceTest" ' + \
'version="0.1"> ' + \
'<linkagesection name="Linkages"/> ' + \
Expand Down Expand Up @@ -895,6 +896,10 @@ def test_search(self):
results6_first_field = json.loads(results6_JSON)["hits"][0]["values"][0]
self.assertEqual(results6_first_field, orig3_first_field)

results7 = search(server = self.server, query = {},
template = TEMPLATE1_NAME)
self.assertEqual(len(results7), 1)


def test_search_simple(self):

Expand Down

0 comments on commit 8020938

Please sign in to comment.