diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3ae56e14c..9503962e1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,12 @@ Changelog 0.21 ==== +0.21.6 +------ +Fixed +^^^^^ +- Fix bug in `pydantic_model_creator` when a foreign key is not included in `include` param. (#1430) + 0.21.5 <../0.21.5>`_ - 2024-07-18 ------ Added diff --git a/tortoise/contrib/pydantic/creator.py b/tortoise/contrib/pydantic/creator.py index 94a46233a..f94418dde 100644 --- a/tortoise/contrib/pydantic/creator.py +++ b/tortoise/contrib/pydantic/creator.py @@ -265,7 +265,7 @@ def field_map_update(keys: tuple, is_relation=True) -> None: # Remove raw fields raw_field = fd.get("raw_field", None) if raw_field is not None and exclude_raw_fields and raw_field != pk_raw_field: - del field_map[raw_field] + field_map.pop(raw_field, None) field_map[n] = fd # Update field definitions from description