customerio-python
customerio-python copied to clipboard
Fix potential AttributeError in session cleanup
Problem
File "customerio/client_base.py", line 112, in _close
...
AttributeError: 'NoneType' object has no attribute 'close'
The _close() method in ClientBase was attempting to call .close() on self._current_session without checking if it was None first. This could lead to an AttributeError when:
- Connection pooling is disabled (
use_connection_pooling=False) - The session hasn't been initialized yet or has been set to
None
Solution
Added a null check to the condition in _close() method to ensure we only attempt to close the session if it actually exists:
# Before
if (not self.use_connection_pooling):
self._current_session.close() # Could raise AttributeError if None
# After
if (not self.use_connection_pooling and self._current_session is not None):
self._current_session.close() # Safe - only called when session exists