I am on occasion seeing a "You have uncommitted work pending. Please commit or rollback before calling out" error during a sequence of callouts that are part of the same transaction. So basically the transaction is going:
callout
callout
callout
update records
However I am now noticing that on those callout methods there is code to update a record holding the OAuth token if the first callout fails due to unauthorized token. This method is tagged as @future(callout=true). So each callout goes:
callout
if unauthorized, callout for authorization, call @future method with updated OAuth token to update a record and save the new auth token
callout again with updated auth token
So there's a chance every now and then that when the OAuth token expires, the next callout could fail because it's running DML in between callouts in the same transaction. I was under the impression that an @future method executes in its own context outside of the transaction, but I am not seeing that happen. Am I misunderstanding the @future annotation?
Thanks