Fix: Set tenant context when x-adcp-tenant header provides direct tenant_id #467
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.
Problem
After PR #464 (tenant isolation fix),
create_media_buyfails with:This worked yesterday but broke after the tenant isolation fix.
Root Cause
When
x-adcp-tenantheader is used with a direct tenant_id (e.g.,tenant_wonderstruck):get_tenant_by_subdomain('tenant_wonderstruck')fails (not a subdomain)get_principal_from_token(token, 'tenant_wonderstruck')calledSolution
get_tenant_by_id()function toconfig_loader.pymain.pyto look up tenant by ID and callset_current_tenant()Changes
src/core/config_loader.py: Addedget_tenant_by_id()helper functionsrc/core/main.py: Fixed tenant context setting for direct tenant_id, added importTesting
principal_8ac9e391/tenant_wonderstruckget_productsendpointget_principal_from_token()callImpact
Fixes authentication for all write operations (create_media_buy, update_media_buy, etc.) when using
x-adcp-tenantheader with direct tenant_id.Fixes regression from PR #464.
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com