From be6dda685eb678140f861264ebefe8e4c971f260 Mon Sep 17 00:00:00 2001 From: saursinh Date: Mon, 8 Jun 2026 11:31:39 +0530 Subject: [PATCH 1/2] Capture environment per-instance to ensure thread-safe configuration persistence --- authorizenet/apicontrollersbase.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/authorizenet/apicontrollersbase.py b/authorizenet/apicontrollersbase.py index bab6e0f..3575d24 100644 --- a/authorizenet/apicontrollersbase.py +++ b/authorizenet/apicontrollersbase.py @@ -118,7 +118,7 @@ def getprettyxmlrequest(self): def execute(self): - self.endpoint = APIOperationBase.__environment + self.endpoint = self._environment anetLogger.debug('Executing http post to url: %s', self.endpoint) @@ -193,8 +193,8 @@ def beforeexecute(self): return @staticmethod - def getmerchantauthentication(self): - return self.__merchantauthentication + def getmerchantauthentication(): + return APIOperationBase.__merchantauthentication @staticmethod def setmerchantauthentication(merchantauthentication): @@ -204,14 +204,14 @@ def setmerchantauthentication(merchantauthentication): def validateandsetmerchantauthentication(self): anetapirequest = apicontractsv1.ANetApiRequest() if (anetapirequest.merchantAuthentication == "null"): - if (self.getmerchantauthentication() != "null"): - anetapirequest.merchantAuthentication = self.getmerchantauthentication() + if (APIOperationBase.getmerchantauthentication() != "null"): + anetapirequest.merchantAuthentication = APIOperationBase.getmerchantauthentication() else: raise ValueError('Merchant Authentication can not be null') return @staticmethod - def getenvironment(self): + def getenvironment(): return APIOperationBase.__environment @@ -233,9 +233,16 @@ def __init__(self, apiRequest): raise ValueError('Input request cannot be null') self._request = apiRequest - __merchantauthentication = apicontractsv1.merchantAuthenticationType() - APIOperationBase.__environment = constants.SANDBOX + # Initialize class environment to SANDBOX if not already set + if APIOperationBase.__environment == "null": + APIOperationBase.__environment = constants.SANDBOX + + # Capture the current class environment into instance variable + # This prevents other threads from resetting the environment after this instance is created + self._environment = APIOperationBase.__environment + + __merchantauthentication = apicontractsv1.merchantAuthenticationType() APIOperationBase.setmerchantauthentication(__merchantauthentication) self.validate() From c87f5ce882ee36c312b88970d1a60adfaec83dfb Mon Sep 17 00:00:00 2001 From: saursinh Date: Mon, 8 Jun 2026 12:13:13 +0530 Subject: [PATCH 2/2] Capture environment per-instance to ensure thread-safe configuration persistence --- authorizenet/apicontrollersbase.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/authorizenet/apicontrollersbase.py b/authorizenet/apicontrollersbase.py index 3575d24..11fc29d 100644 --- a/authorizenet/apicontrollersbase.py +++ b/authorizenet/apicontrollersbase.py @@ -7,6 +7,7 @@ import logging import pyxb import sys +import threading import xml.dom.minidom import requests from lxml import objectify @@ -75,6 +76,7 @@ class APIOperationBase(APIOperationBaseInterface): __metaclass__ = abc.ABCMeta __initialized = False + __environment_lock = threading.Lock() __merchantauthentication = "null" __environment = "null" @@ -118,7 +120,12 @@ def getprettyxmlrequest(self): def execute(self): - self.endpoint = self._environment + # Read environment at execute time with lock to ensure consistency + with APIOperationBase.__environment_lock: + # Initialize class environment to SANDBOX if not already set + if APIOperationBase.__environment == "null": + APIOperationBase.__environment = constants.SANDBOX + self.endpoint = APIOperationBase.__environment anetLogger.debug('Executing http post to url: %s', self.endpoint) @@ -212,12 +219,14 @@ def validateandsetmerchantauthentication(self): @staticmethod def getenvironment(): - return APIOperationBase.__environment + with APIOperationBase.__environment_lock: + return APIOperationBase.__environment @staticmethod def setenvironment(userenvironment): - APIOperationBase.__environment = userenvironment + with APIOperationBase.__environment_lock: + APIOperationBase.__environment = userenvironment return def __init__(self, apiRequest): @@ -234,14 +243,6 @@ def __init__(self, apiRequest): self._request = apiRequest - # Initialize class environment to SANDBOX if not already set - if APIOperationBase.__environment == "null": - APIOperationBase.__environment = constants.SANDBOX - - # Capture the current class environment into instance variable - # This prevents other threads from resetting the environment after this instance is created - self._environment = APIOperationBase.__environment - __merchantauthentication = apicontractsv1.merchantAuthenticationType() APIOperationBase.setmerchantauthentication(__merchantauthentication) self.validate()