Skip to content

Commit 05daf2e

Browse files
committed
Skip trying to cast fields that have a model type annotation.
1 parent 14512d1 commit 05daf2e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

django_unicorn/typer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ def cast_value(type_hint, value):
138138
pass
139139
else:
140140
if issubclass(type_hint, Model):
141-
if isinstance(value, dict):
142-
value = type_hint(**value)
143-
break
144-
else:
145-
continue
141+
continue
146142

147143
value = type_hint(value)
148144
break

tests/test_typer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ def test_cast_value_model_none():
7171
assert actual is None
7272

7373

74+
def test_cast_value_model_dict():
75+
example_class = ExampleClass()
76+
type_hints = typing_get_type_hints(example_class)
77+
type_hint = type_hints["a_model"]
78+
79+
actual = cast_value(type_hint, {"id": 1})
80+
81+
assert actual == {"id": 1}
82+
83+
7484
def test_cast_value_optional():
7585
type_hints = typing_get_type_hints(ExampleClass())
7686
type_hint = type_hints["optional_model"]

0 commit comments

Comments
 (0)