From a7ebbbc8460dc160990d406f9cb06d9e2f5f064e Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 10 Sep 2024 10:32:43 +0200 Subject: [PATCH] Fix compatibility issue with fastapi >= 0.112.3 If fastapi is installed we path the method used to build the field definition from model to ensure that the registry is initialized. From version 0.112.3 the patched method 'create_response_field' has been renamed 'create_model_field'. This change ensure that this new method is also patched fixes #20 --- news/20.bugfix.rst | 1 + src/extendable_pydantic/_patch.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 news/20.bugfix.rst diff --git a/news/20.bugfix.rst b/news/20.bugfix.rst new file mode 100644 index 0000000..7d73dcd --- /dev/null +++ b/news/20.bugfix.rst @@ -0,0 +1 @@ +Fixes compatibility issue with fastapi version >= 0.112.3 diff --git a/src/extendable_pydantic/_patch.py b/src/extendable_pydantic/_patch.py index 2024275..561873c 100644 --- a/src/extendable_pydantic/_patch.py +++ b/src/extendable_pydantic/_patch.py @@ -66,6 +66,12 @@ def _create_response_field_wrapper(wrapped, instance, args, kwargs): _resolve_model_fields_annotation([field]) return field + # fastapi < 0.112.3 wrapt.wrap_function_wrapper( utils, "create_response_field", _create_response_field_wrapper ) + + # fastapi >= 0.112.3 + wrapt.wrap_function_wrapper( + utils, "create_model_field", _create_response_field_wrapper + )