Skip to content

Commit 568dc45

Browse files
committed
fix: Allow setting max_connections from config when in autodiscover mode
1 parent 7401f51 commit 568dc45

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

exchangelib/account.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,16 @@ def __init__(
166166
raise InvalidTypeError("config", config, Configuration)
167167
if autodiscover:
168168
if config:
169-
auth_type, retry_policy, version = config.auth_type, config.retry_policy, config.version
169+
auth_type, retry_policy, version, max_connections = (
170+
config.auth_type,
171+
config.retry_policy,
172+
config.version,
173+
config.max_connections,
174+
)
170175
if not credentials:
171176
credentials = config.credentials
172177
else:
173-
auth_type, retry_policy, version = None, None, None
178+
auth_type, retry_policy, version, max_connections = None, None, None, None
174179
self.ad_response, self.protocol = Autodiscovery(
175180
email=primary_smtp_address, credentials=credentials
176181
).discover()
@@ -180,6 +185,7 @@ def __init__(
180185
self.protocol.config.retry_policy = retry_policy
181186
if version:
182187
self.protocol.config.version = version
188+
self.protocol.max_connections = max_connections
183189
primary_smtp_address = self.ad_response.autodiscover_smtp_address
184190
else:
185191
if not config:

exchangelib/protocol.py

+9
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ def credentials(self, value):
131131
self.config._credentials = value
132132
self.close()
133133

134+
@property
135+
def max_connections(self):
136+
return self._session_pool_maxsize
137+
138+
@max_connections.setter
139+
def max_connections(self, value):
140+
with self._session_pool_lock:
141+
self._session_pool_maxsize = value or self.SESSION_POOLSIZE
142+
134143
@property
135144
def retry_policy(self):
136145
return self.config.retry_policy

tests/test_autodiscover.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -847,16 +847,22 @@ def test_redirect_url_is_valid(self, m):
847847
self.assertTrue(a._redirect_url_is_valid(self.account.protocol.config.service_endpoint))
848848

849849
def test_protocol_default_values(self):
850-
# Test that retry_policy and auth_type always get a value regardless of how we create an Account
851-
self.get_account()
852-
a = Account(
853-
self.account.primary_smtp_address,
854-
autodiscover=True,
855-
config=self.account.protocol.config,
856-
)
857-
self.assertIsNotNone(a.protocol.auth_type)
858-
self.assertIsNotNone(a.protocol.retry_policy)
850+
# Test that retry_policy, auth_type and max_connections always get values regardless of how we create an Account
851+
_max_conn = self.account.protocol.config.max_connections
852+
try:
853+
self.account.protocol.config.max_connections = 3
854+
a = Account(
855+
self.account.primary_smtp_address,
856+
autodiscover=True,
857+
config=self.account.protocol.config,
858+
)
859+
self.assertIsNotNone(a.protocol.auth_type)
860+
self.assertIsNotNone(a.protocol.retry_policy)
861+
self.assertEqual(a.protocol._session_pool_maxsize, 3)
862+
finally:
863+
self.account.protocol.config.max_connections = _max_conn
859864

860865
a = Account(self.account.primary_smtp_address, autodiscover=True, credentials=self.account.protocol.credentials)
861866
self.assertIsNotNone(a.protocol.auth_type)
862867
self.assertIsNotNone(a.protocol.retry_policy)
868+
self.assertEqual(a.protocol._session_pool_maxsize, a.protocol.SESSION_POOLSIZE)

0 commit comments

Comments
 (0)