Skip to content

Commit 7c8d67b

Browse files
authored
Merge pull request #42 from marklogic/feature/remove-mixed
Removed "mixed" as an option for "format"
2 parents baed0c9 + 7fbe6e7 commit 7c8d67b

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

docs/rows.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,3 @@ selected via a `format` argument. The following table defined the possible value
149149
| `xml` | XML document defining the columns and rows. |
150150
| `csv` | CSV text with the first row defining the columns. |
151151
| `json-seq` | A [line-delimited JSON sequence](https://datatracker.ietf.org/doc/html/rfc7464) with the first row defining the columns. |
152-
| `mixed` | TODO Seems like we should remove this as it does the same thing as "return_response". |

marklogic/rows.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class RowManager:
11-
1211
def __init__(self, session: Session):
1312
self._session = session
1413

@@ -17,15 +16,13 @@ def __init__(self, session: Session):
1716
"xml": "application/xml",
1817
"csv": "text/csv",
1918
"json-seq": "application/json-seq",
20-
"mixed": "application/xml, multipart/mixed",
2119
}
2220

2321
__query_format_switch = {
2422
"json": lambda response: response.json(),
2523
"xml": lambda response: response.text,
2624
"csv": lambda response: response.text,
2725
"json-seq": lambda response: response.text,
28-
"mixed": lambda response: response,
2926
}
3027

3128
def query(
@@ -37,7 +34,7 @@ def query(
3734
graphql: str = None,
3835
format: str = "json",
3936
return_response: bool = False,
40-
**kwargs
37+
**kwargs,
4138
):
4239
"""
4340
Sends a query to an endpoint at the MarkLogic rows service defined at
@@ -56,8 +53,9 @@ def query(
5653
:param graphql: a GraphQL query string. This is the query string
5754
only, not the entire query JSON object. See
5855
https://docs.marklogic.com/REST/POST/v1/rows/graphql for more information.
59-
:param format: defines the format of the response. If a GraphQL query is
60-
submitted, this parameter is ignored and a JSON response is always returned.
56+
:param format: defines the format of the response. Valid values are "json",
57+
"xml", "csv", and "json-seq". If a GraphQL query is submitted, this parameter
58+
is ignored and a JSON response is always returned.
6159
:param return_response: boolean specifying if the entire original response
6260
object should be returned (True) or if only the data should be returned (False)
6361
upon a success (2xx) response. Note that if the status code of the response is
@@ -73,7 +71,14 @@ def query(
7371
request_info = self.__get_request_info(dsl, plan, sql, sparql)
7472
data = request_info["data"]
7573
headers["Content-Type"] = request_info["content-type"]
76-
headers["Accept"] = RowManager.__accept_switch.get(format)
74+
if format:
75+
value = RowManager.__accept_switch.get(format)
76+
if value is None:
77+
msg = f"Invalid value for 'format' argument: {format}; "
78+
msg += "must be one of 'json', 'xml', 'csv', or 'json-seq'."
79+
raise ValueError(msg)
80+
else:
81+
headers["Accept"] = value
7782

7883
response = self._session.post(path, headers=headers, data=data, **kwargs)
7984
if response.ok and not return_response:

tests/test_rows.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def test_dsl_json_seq(client):
4444
verify_four_musicians_are_returned_in_json_seq(data)
4545

4646

47-
def test_dsl_mixed(client):
48-
response = client.rows.query(dsl_query, format="mixed")
49-
verify_four_musicians_are_returned_in_json(
50-
response.json(), "test.musician.lastName"
51-
)
47+
def test_invalid_format(client):
48+
with raises(
49+
ValueError, match="Invalid value for 'format' argument: invalid; must be one of"
50+
):
51+
client.rows.query(dsl_query, format="invalid")
5252

5353

5454
def test_serialized_default(client):

0 commit comments

Comments
 (0)