Repository navigation
Fix inconsistent base_url behavior in module client and OpenAIClient - #2157
SmartManoj wants to merge 2 commits into
Conversation
Fixes openai#1373 Update `base_url` behavior to enforce trailing slash in module client * Modify `src/openai/__init__.py` to enforce a trailing slash for `base_url` in the `_ModuleClient` class. * Add a helper method `_enforce_trailing_slash` to the `_ModuleClient` class. * Update tests in `tests/test_module_client.py` to verify the consistent behavior of `base_url` in both module client and `OpenAIClient`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/openai/openai-python/issues/1373?shareId=XXXX-XXXX-XXXX-XXXX).
|
AI-assisted independent offline check at 12/12 URL controls pass on this head versus 10/12 on pinned main. Direct-client and module-client controls cover root, /v1 and nested /a/b base URLs, each with/without a trailing slash. The module baseline joins the two path-without-slash cases as /v1models and /a/bmodels; this head prepares /v1/models and /a/b/models while the direct-client and trailing-slash controls remain unchanged. Scope: Actual local _prepare_url helper on direct and module client objects. Fictional host/key values; in-process module globals restored and clients closed. No requests, Azure module variant or query/fragment-containing base URL policy proof. Python 3.14.7 / Pydantic 2.13.5 and shared local dependencies; this is a bounded matrix, not a full SDK suite or historical dependency matrix. Network denied by the sandbox. Standalone reproducer (run separately with each source tree on PYTHONPATH)import json,openai
rows=[]
saved=(openai.api_key,openai.base_url)
try:
for kind in ['direct','module']:
for url in ['https://example.invalid','https://example.invalid/','https://example.invalid/v1','https://example.invalid/v1/','https://example.invalid/a/b','https://example.invalid/a/b/']:
openai.api_key='fictional';openai.base_url=url
client=(openai.OpenAI if kind=='direct' else openai._ModuleClient)(api_key='fictional',base_url=url)
actual=str(client._prepare_url('/models'));expected=url.rstrip('/')+'/models'
rows.append({'kind':kind,'base_url':url,'prepared':actual,'expected':expected,'pass':actual==expected});client.close()
finally:openai.api_key,openai.base_url=saved
print(json.dumps({'cases':rows,'passed':sum(x['pass'] for x in rows),'failed':sum(not x['pass'] for x in rows),'scope':'Actual module/direct client local URL preparation; fictional values, globals restored, no endpoint request/query-component policy proof.'})) |
|
Thanks for catching the missing slash. I confirmed that the module client can still turn |
Fixes #1373
Update
base_urlbehavior to enforce trailing slash in module clientsrc/openai/__init__.pyto enforce a trailing slash forbase_urlin the_ModuleClientclass._enforce_trailing_slashto the_ModuleClientclass.tests/test_module_client.pyto verify the consistent behavior ofbase_urlin both module client andOpenAIClient.For more details, open the Copilot Workspace session.