fix(salesforce): fall back to userinfo endpoint when instance_url missing from credentials#272
fix(salesforce): fall back to userinfo endpoint when instance_url missing from credentials#272Shubhank-Jonnada wants to merge 2 commits intomasterfrom
Conversation
🔍 Integration Validation ResultsCommit: Changed directories:
✅ Structure Check output✅ Code Check output✅ Tests output✅ README Check output✅ Version Check output |
…sing from credentials
b74cee6 to
78922ab
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b74cee610f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
ProRedCat
left a comment
There was a problem hiding this comment.
Instead of fixing this on the integration side, we should instead make it so that the instance url is stored in the metadata field which can then be accessed here
This way we don't have to do a request to fetch what the instance URL is. We have a few integrations that follow this pattern already (see Discord)
Summary
The Salesforce integration was intermittently failing with
instance_url not found in credentials or metadataacross all actions. The platform's OAuth layer does not always forwardinstance_urlin the credentials dict — most notably after a token refresh, where only standard OAuth fields are returned. This fix makes the integration self-sufficient: wheninstance_urlisn't available through the normal channels, it derives it from Salesforce's/services/oauth2/userinfoendpoint using the access token that's always present.Root Cause
_get_token_and_instancewas synchronous and raised immediately ifinstance_urlwasn't found incredentials,context.metadata, orSALESFORCE_INSTANCE_URL. After a token refresh the platform reconstructs credentials from the refresh response, which may omit non-standard fields likeinstance_url, causing every action to fail until the user reconnected.Changes
salesforce/salesforce.py— made_get_token_and_instanceasync; added_resolve_instance_urlfallback that callshttps://login.salesforce.com/services/oauth2/userinfoand parsesurls.restto extract the instance hostname; updated all 7 call sites toawaitBehaviour
instance_urlin credentialsinstance_urlin metadata/envinstance_urlmissing (e.g. post-refresh)Notes
ctx.metadata["instance_url"]which still resolves on the second check