diff options
author | Alon Diamant <diamant.alon@gmail.com> | 2022-03-14 13:52:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 13:52:51 +0200 |
commit | a081173b650dd73fca06d419156ab525bc1c2200 (patch) | |
tree | 9d0b716a2746662bcbfc7240824322eb3db4079d | |
parent | 934c6891c221157985743db76a2c9edb93ef45d6 (diff) | |
download | redis-py-a081173b650dd73fca06d419156ab525bc1c2200.tar.gz |
Fix: avoiding issue with PytestUnraisableExceptionWarning (#1458)
* Fix: avoiding issue with PytestUnraisableExceptionWarning that is raised because of __del__() calling self.close() in Redis class, as the self.connection attribute was not set due to early failure in the Redis() constructor. Example: calling redis.StrictRedis(**connectionInfo) in a constructor, with connectionInfo={'hog':'cat'}
* linters
* linters
Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
-rwxr-xr-x | redis/client.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index de0180c..c51ab91 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1151,6 +1151,12 @@ class Redis(AbstractRedis, RedisModuleCommands, CoreCommands, SentinelCommands): self.close() def close(self): + # In case a connection property does not yet exist + # (due to a crash earlier in the Redis() constructor), return + # immediately as there is nothing to clean-up. + if not hasattr(self, "connection"): + return + conn = self.connection if conn: self.connection = None |