Skip to content

Commit 8700413

Browse files
committed
Check for Pydantic 2.0 sentinel in typecodes.
1 parent bb8b82c commit 8700413

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/view/_loader.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,19 +307,23 @@ def __view_construct__(**kwargs):
307307
) or getattr(tp, "model_fields", None)
308308
if pydantic_fields:
309309
tps = {}
310+
try:
311+
from pydantic_core import PydanticUndefined
312+
except ImportError:
313+
PydanticUndefined = None
310314

311315
for k, v in pydantic_fields.items():
312316
outer_type = getattr(v, "outer_type_", None)
313317
if not outer_type:
314318
outer_type = v.annotation
315-
if (not v.default) and (not v.default_factory):
319+
default_not_set = v.default in (None, PydanticUndefined)
320+
if default_not_set and (not v.default_factory):
316321
tps[k] = outer_type
317322
else:
318323
tps[k] = BodyParam(
319324
outer_type,
320-
v.default or v.default_factory,
325+
v.default_factory if default_not_set else v.default,
321326
)
322-
323327
doc = {}
324328
codes.append((TYPECODE_CLASS, tp, _format_body(tps, doc, tp)))
325329
setattr(tp, "_view_doc", doc)

0 commit comments

Comments
 (0)