Skip to content

Release the imported settings class during interpreter cleanup - #988

Open
amadfida wants to merge 1 commit into
ets-labs:masterfrom
amadfida:codex/fix-settings-shutdown
Open

amadfida wants to merge 1 commit into
ets-labs:masterfrom
amadfida:codex/fix-settings-shutdown

Conversation

@amadfida

Copy link
Copy Markdown

PydanticSettings is stored in a cdef object global, retaining BaseSettings outside the generated module's GC traversal and clearing. Objects reachable through that class can consequently survive interpreter teardown.

Store the imported class in the Python module dictionary so it remains available during normal execution and atexit callbacks, then participates in ordinary interpreter cleanup.

The regression test uses a synthetic settings class and finalization marker. It verifies that configuration providers work in exit callbacks registered before and after the providers import, and that the marker is subsequently finalized. It fails with the unchanged release and passes with this change on macOS and Linux using Python 3.13.

Validation: full upstream unit suite (1386 passed, 2 skipped), Pydantic 1 configuration suite (204 passed), and unchanged-versus-fixed Linux builds. Existing deprecation warnings remain visible.

This branch has not been deployed

No deployments
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.

1 participant