Skip to content

fix: handle None by_alias in model_dump for FastAPI contexts#1165

Open
thecaptain789 wants to merge 1 commit intoanthropics:mainfrom
thecaptain789:fix-by-alias-none
Open

fix: handle None by_alias in model_dump for FastAPI contexts#1165
thecaptain789 wants to merge 1 commit intoanthropics:mainfrom
thecaptain789:fix-by-alias-none

Conversation

@thecaptain789
Copy link

When calling model_dump with by_alias=None (the default), the pydantic-core serializer in certain async contexts (like FastAPI) can fail with 'NoneType' cannot be converted to 'PyBool'.

This applies the same pattern already used in _models.py where by_alias is explicitly converted:

by_alias=by_alias if by_alias is not None else False

Fixes #1160

When calling model_dump with by_alias=None (the default), the
pydantic-core serializer in certain contexts (like FastAPI) can
fail with 'NoneType cannot be converted to PyBool'.

This matches the pattern already used in _models.py where by_alias
is explicitly converted: by_alias if by_alias is not None else False

Fixes anthropics#1160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: argument 'by_alias': 'NoneType' object cannot be converted to 'PyBool' when using SDK in FastAPI context

1 participant