Skip to content

Commit c460f65

Browse files
committed
do not attempt to parse named parameters to call_command
1 parent ebf5337 commit c460f65

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

django_typer/__init__.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ class _DjangoAdapterMixin(with_typehint(CoreTyperGroup)): # type: ignore[misc]
364364
context_class: t.Type[click.Context] = Context
365365
django_command: "TyperCommand"
366366
callback_is_method: bool = True
367-
param_map: t.Dict[str, click.Parameter] = {}
368367

369368
class Converter:
370369
"""
@@ -417,16 +416,14 @@ def call_with_self(*args, **kwargs):
417416
return callback(
418417
*args,
419418
**{
420-
# process supplied parameters incase they need type conversion
421-
param: (
422-
(
423-
self.param_map[param].process_value(ctx, val)
424-
if param in self.param_map
425-
else val
426-
)
427-
if param in ctx.supplied_params
428-
else val
429-
)
419+
# we could call param.process_value() here to allow named
420+
# parameters to be passed as their unparsed string values,
421+
# we don't because this forces some weird idempotency on custom
422+
# parsers that might make errors more frequent for users and also
423+
# this would be inconsistent with call_command behavior for BaseCommands
424+
# which expect the parsed values to be passed by name. Unparsed values can
425+
# always be passed as argument strings.
426+
param: val
430427
for param, val in kwargs.items()
431428
if param in expected
432429
},
@@ -450,7 +447,6 @@ def call_with_self(*args, **kwargs):
450447
callback=call_with_self,
451448
**kwargs,
452449
)
453-
self.param_map = {param.name: param for param in self.params}
454450

455451

456452
class TyperCommandWrapper(_DjangoAdapterMixin, CoreTyperCommand):

django_typer/tests/tests.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,10 +1241,6 @@ def test_command_line(self, settings=None):
12411241
call_command("groups", "echo", "hey!", echoes=5).strip(),
12421242
("hey! " * 5).strip(),
12431243
)
1244-
self.assertEqual(
1245-
call_command("groups", "echo", "hey!", echoes="5").strip(),
1246-
("hey! " * 5).strip(),
1247-
)
12481244
else:
12491245
self.assertIn("UsageError", result[1])
12501246
with self.assertRaises(TypeError):
@@ -1281,7 +1277,7 @@ def test_command_line(self, settings=None):
12811277

12821278
self.assertEqual(
12831279
call_command(
1284-
"groups", "math", "multiply", "1.2", "3.5", " -12.3", precision="5"
1280+
"groups", "math", "--precision=5", "multiply", "1.2", "3.5", " -12.3"
12851281
),
12861282
"-51.66000",
12871283
)
@@ -1884,20 +1880,6 @@ def test_app_label_parser_completers(self):
18841880
},
18851881
)
18861882

1887-
self.assertEqual(
1888-
json.loads(
1889-
call_command(
1890-
"completion",
1891-
"django_typer_tests_polls",
1892-
option="django_typer_tests_test_app",
1893-
)
1894-
),
1895-
{
1896-
"django_apps": ["django_typer_tests_polls"],
1897-
"option": "django_typer_tests_test_app",
1898-
},
1899-
)
1900-
19011883
self.assertEqual(
19021884
json.loads(
19031885
call_command(

0 commit comments

Comments
 (0)