Skip to content

Commit 97aba54

Browse files
SmittieCclaude
andcommitted
chore: set DEFER_PYDANTIC_BUILD in deployment instead of settings.py
The DEFER_PYDANTIC_BUILD=0 workaround for the OpenAI SDK MockValSer error is applied manually in the deployment config, so drop the os.environ.setdefault from config/settings.py. Keep the documented entry in .env.example (without the now-removed settings.py reference). See openai/openai-python#1306. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 858b45a commit 97aba54

2 files changed

Lines changed: 3 additions & 10 deletions

File tree

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ APP_IP=
129129
## providers and by integration tests in apps/service_providers/tests/test_llm_integration.py).
130130
## Set the keys for whichever providers you want available; unset providers are skipped.
131131

132-
## Forces the OpenAI SDK to build its Pydantic models eagerly instead of deferring, which otherwise
133-
## causes "TypeError: 'MockValSer' object is not an instance of 'SchemaSerializer'" when serializing
134-
## responses. Defaulted to "0" in config/settings.py; only set here to override. See openai/openai-python#1306.
132+
## Set to "0" to force the OpenAI SDK to build its Pydantic models eagerly instead of deferring,
133+
## which otherwise causes "TypeError: 'MockValSer' object is not an instance of 'SchemaSerializer'"
134+
## when serializing responses. See openai/openai-python#1306.
135135
# DEFER_PYDANTIC_BUILD=0
136136

137137
# OpenAI

config/settings.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
env = environ.Env()
2828
env.read_env(os.path.join(BASE_DIR, ".env"))
2929

30-
# The OpenAI SDK defers building its Pydantic models by default (defer_build=True), which leaves
31-
# nested/generic response models with a MockValSer placeholder serializer. Serializing such a
32-
# response (e.g. langchain_openai calling response.model_dump() on a ParsedResponse) then raises
33-
# "TypeError: 'MockValSer' object is not an instance of 'SchemaSerializer'". Building eagerly avoids
34-
# this. Must be set before `openai` is first imported, hence here. See openai/openai-python#1306.
35-
os.environ.setdefault("DEFER_PYDANTIC_BUILD", "0")
36-
3730
# Quick-start development settings - unsuitable for production
3831
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
3932

0 commit comments

Comments
 (0)