Repository navigation
feat(integrations): Defer OpenAI integration setup until openai is imported - #8341
Draft
ericapisani wants to merge 2 commits into
Draft
ericapisani wants to merge 2 commits into
ericapisani wants to merge 2 commits into
Conversation
…ported Behind the deferred_auto_enabling_integrations experiment, init() no longer imports openai just because the OpenAI integration is auto-enabling. A sys.meta_path finder wraps the openai loader and sets the integration up once the application imports openai itself. Integrations not in the trigger mapping keep the eager setup. Refs TEL-133
Contributor
Coverage Results 📊✅ 139568 passed | ⏭️ 7905 skipped | Total: 147473 | Pass Rate: 94.64% | Execution Time: 867m 22s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 85.87% (79 of 92 changed executable lines covered; target 80%). Changed files with executable lines (1)
Coverage diff@@ Coverage Diff @@
## master #8341 +/-##
==========================================
Coverage 90.23% 90.23% —%
==========================================
Files 203 203 —
Tracked lines 27349 27438 +89
Branches 10252 10286 +34
==========================================
+ Hits 24675 24756 +81
- Misses 2674 2682 +8
- Partials 1557 1567 +10Generated by Coverage Action |
Leave the deferred setup finder on sys.meta_path once installed. Removing it while another thread iterates sys.meta_path can make that thread skip the next finder, and the finder returns early when nothing is pending. Treat any exception from find_spec at init as the library not being installed, and drop a pending integration whose loader has no exec_module instead of leaving it pending forever. Deferred setup now reads options from the client it registers the integration on. Refs TEL-133
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Behind the
deferred_auto_enabling_integrationsexperiment,init()no longer imports openai just because the OpenAI integration is auto-enabling. Asys.meta_pathfinder wraps the openai loader and sets the integration up once the application imports openai itself. Integrations not in the trigger mapping keep the eager setup.First PR in a stack of two; the remaining AI integrations follow in #8342.
The finder stays on
sys.meta_pathonce installed (it returnsNoneimmediately when nothing is pending), because removing it while another thread is iteratingmeta_pathcan make that import skip a finder. Deferredsetup_once()runs without_installer_lock, since setup that imports another trigger would otherwise deadlock.Benchmark
Python 3.14, Django 6.1.3 + celery 5.7.0 + openai 3.57.0, app code never imports openai, median of 15 fresh processes:
init()timeinit()Verified on CPython 3.15.2 that
lazy import openaifires the hook on first use.Fixes TEL-133
Refs #6263