Skip to content

Commit 4dc59c7

Browse files
committed
Remove support for passing post data as arguments
Temporarily deprecate support for passing post data as arguments. This was mainly because of strange Typer error "RuntimeError: Type not yet supported: <class 'typer.models.Context'>" when elapi is run on Python 3.9. Upon diagnosing, the culprit turned out to be the use of typer.Context which elapi cli post command was using. typer.Context works fine on Python 3.11. Support for said feature should be brought back once Python 3.11 becomes the default on Debian.
1 parent f539377 commit 4dc59c7

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ $ elapi get experiments --export ~/Downoads/experiments.json
8989
We can create a new user by the name 'John Doe'.
9090

9191
```shell
92-
$ elapi post users --firstname John --lastname Doe --email "test_test@example.com" --usergroup 4
93-
# usergroup 4 refers to the user's permission group
92+
$ elapi post users -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'
9493
```
9594

9695
### Bill teams

src/elapi/cli/_doc.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"ID will be returned. E.g., user ID, team ID, experiments ID.",
1515
"unit_id_post": "ID for one of the preceding endpoints. If provided, `POST` request will be made against that "
1616
"specific ID. E.g., events ID,.",
17-
"data": f"HTTP POST data. There are two ways to pass the data. 1. With `--data` or `-d` option followed "
18-
f"by the JSON content like with `curl`. E.g., "
19-
f"`{APP_NAME} post teams -d '{{\"name\": \"Alpha\"}}'`, 2. As regular options. E.g., "
20-
f"`{APP_NAME} post teams --name Alpha`.",
17+
# "data": f"HTTP POST data. There are two ways to pass the data. 1. With `--data` or `-d` option followed "
18+
# f"by the JSON content like with `curl`. E.g., "
19+
# f"`{APP_NAME} post teams -d '{{\"name\": \"Alpha\"}}'`, 2. As regular options. E.g., "
20+
# f"`{APP_NAME} post teams --name Alpha`.",
21+
"data": f"HTTP POST data. This works similar to how data is passed to `curl`. E.g., "
22+
f"`{APP_NAME} post teams -d '{{\"name\": \"Alpha\"}}'`,",
2123
"export": "Export output to a location.\n",
2224
"invoice_export": "Export output to a location. Invoices are **always exported** by default.\n",
2325
"export_details": f"- If _'--export'_ is passed without any following value, then it acts as a flag, and "

src/elapi/cli/elapi.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def post(
173173
] = None,
174174
json_: Annotated[
175175
str, typer.Option("--data", "-d", help=docs["data"], show_default=False)
176-
] = "",
177-
data: typer.Context = None,
176+
],
177+
# data: typer.Context = None, TODO: To be re-enabled in Python 3.11
178178
data_format: Annotated[
179179
str,
180180
typer.Option("--format", "-F", help=docs["data_format"], show_default=False),
@@ -192,7 +192,7 @@ def post(
192192
193193
With `elapi` you can do the following:
194194
<br/>
195-
`$ elapi post users --firstname John --lastname Doe --email "john_doe@email.com"` will create a new user.
195+
`$ elapi post users -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'` will create a new user.
196196
"""
197197
import ast
198198
from ..api import POSTRequest
@@ -203,12 +203,14 @@ def post(
203203
validate_config = Validate(HostIdentityValidator())
204204
validate_config()
205205

206-
if json_:
207-
valid_data: dict = ast.literal_eval(json_)
208-
else:
209-
data_keys: list[str, ...] = [_.removeprefix("--") for _ in data.args[::2]]
210-
data_values: list[str, ...] = data.args[1::2]
211-
valid_data: dict[str:str, ...] = dict(zip(data_keys, data_values))
206+
# if json_:
207+
valid_data: dict = ast.literal_eval(json_)
208+
# else:
209+
# TODO: Due to strange compatibility issue between typer.context and python 3.9,
210+
# passing json_ as arguments is temporarily deprecated.
211+
# data_keys: list[str, ...] = [_.removeprefix("--") for _ in data.args[::2]]
212+
# data_values: list[str, ...] = data.args[1::2]
213+
# valid_data: dict[str:str, ...] = dict(zip(data_keys, data_values))
212214
session = POSTRequest()
213215
raw_response = session(endpoint, unit_id, **valid_data)
214216
format = Format(data_format)

0 commit comments

Comments
 (0)