forcedotcom / SalesforcePy

An absurdly simple package for making Salesforce Rest API calls.
BSD 3-Clause "New" or "Revised" License
106 stars 42 forks source link

Session expired or invalid #56

Open chripede opened 3 years ago

chripede commented 3 years ago

When using this to bulk send data (one item at a time) I am hit with

Exception: [{'message': 'Session expired or invalid', 'errorCode': 'INVALID_SESSION_ID'}]

regularly.

For each request I do with SalesforceClient as client so there is no way it will actually expire, unless it does within a second?

caffalaughrey commented 3 years ago

The extent to which the client currently manages the session is:

To handle your scenario where session timeout is a factor and a fresh session id is needed, we would need to support the refresh token flow. I'd be open to it

ericbn commented 1 year ago

I had "INVALID_SESSION_ID: Session expired or invalid" errors before, and found out the root cause was having concurrent sessions and one of them calling logout() while the other sessions were still in use, and this invalidated them. Also, if you're using Client as a context manager, logout() will be called when the context exists.

See https://developer.salesforce.com/forums/?id=906F00000005LQoIAM

Never had a single INVALID_SESSION_ID again after I stopped calling logout() or using Client as a context manager.

Given this, I'd say that logout() is evil and should never be called. Automatically refreshing the token would be hiding the issue, so I'm not if favor of adding that feature.

* By "using Client as a context manager" I mean:

with sfdc.client(**client_args) as client:
    ...