Skip to content

Commit d07a218

Browse files
authored
Merge pull request #50 from marklogic/feature/rows-none
Returning None instead of empty array
2 parents 7a1c408 + 7bad604 commit d07a218

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

marklogic/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def eval(
100100
"""
101101
Send a script to MarkLogic via a POST to the endpoint
102102
defined at https://docs.marklogic.com/REST/POST/v1/eval. Must define either
103-
'javascript' or 'xquery'.
103+
'javascript' or 'xquery'. Returns a list, unless no content is returned in
104+
which case None is returned.
104105
105106
:param javascript: a JavaScript script
106107
:param xquery: an XQuery script
@@ -141,7 +142,8 @@ def invoke(
141142
"""
142143
Send a script (XQuery or JavaScript) and possibly a dict of vars
143144
to MarkLogic via a POST to the endpoint defined at
144-
https://docs.marklogic.com/REST/POST/v1/eval.
145+
https://docs.marklogic.com/REST/POST/v1/eval. Returns a list, unless no content
146+
is returned in which case None is returned.
145147
146148
:param module: The URI of a module in the modules database of the app server
147149
:param vars: a dict containing variables to include

marklogic/internal/eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def process_multipart_mixed_response(response: Response) -> list:
2020
MarkLogic server.
2121
"""
2222
if response_has_no_content(response):
23-
return []
23+
return None
2424

2525
parts = MultipartDecoder.from_response(response).parts
2626
transformed_parts = []

marklogic/rows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def query(
9494
)
9595
if response.ok and not return_response:
9696
if response_has_no_content(response):
97-
return []
97+
return None
9898
return (
9999
response.json()
100100
if graphql

tests/test_eval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_javascript_vars(client):
100100

101101
def test_xquery_empty_sequence(client):
102102
parts = client.eval(xquery="()")
103-
assert [] == parts
103+
assert parts is None
104104

105105

106106
def test_javascript_empty_array(client):
@@ -110,7 +110,7 @@ def test_javascript_empty_array(client):
110110

111111
def test_javascript_empty_sequence(client):
112112
parts = client.eval(javascript="Sequence.from([])")
113-
assert [] == parts
113+
assert parts is None
114114

115115

116116
def test_base64Binary(client):

tests/test_rows.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_dsl_default(client):
1717
def test_no_rows_returned(client):
1818
query = 'op.fromView("test", "musician").where(op.eq(op.col("lastName"), "Smith"))'
1919
results = client.rows.query(query)
20-
assert [] == results
20+
assert results is None
2121

2222

2323
def test_dsl_default_return_response(client):
@@ -98,7 +98,7 @@ def test_transaction(client):
9898
query = f'op.fromView("test", "musician")'
9999
query = f'{query}.where(op.eq(op.col("lastName"), "{lastName}"))'
100100
results = client.rows.query(query, tx=tx)
101-
assert len(results) == 0
101+
assert results is None
102102

103103
perms = {"python-tester": ["read", "update"]}
104104
doc = Document(uri, content, permissions=perms)
@@ -109,7 +109,7 @@ def test_transaction(client):
109109

110110
client.delete("/v1/documents", params={"uri": uri, "txid": tx.id})
111111
results = client.rows.query(query, tx=tx)
112-
assert len(results) == 0
112+
assert results is None
113113

114114

115115
def verify_four_musicians_are_returned_in_json(data, column_name):

0 commit comments

Comments
 (0)