redis / redis-py

Redis Python client
MIT License
12.54k stars 2.51k forks source link

exception message is printed even when using try-except #2021

Closed GuyAv46 closed 1 year ago

GuyAv46 commented 2 years ago

Version: redis-py 4.1.4 , redis version 6.2.6?

Platform: Python 3.8.10 on Ubuntu 20.04

Description: I have a piece of code that tries to create a redisearch index and catch the exception "Index already exists" if it being raised.

try:
    if self.algo == "HNSW":
        self.redis.execute_command('FT.CREATE', self.index_name, 'SCHEMA', 'vector', 'VECTOR', self.algo, '12', 'TYPE', 'FLOAT32', 'DIM', len(X[0]), 'DISTANCE_METRIC', self.metric, 'INITIAL_CAP', len(X), 'M', self.method_param['M'] , 'EF_CONSTRUCTION', self.method_param["efConstruction"], target_nodes='random')
    elif self.algo == "FLAT":
        self.redis.execute_command('FT.CREATE', self.index_name, 'SCHEMA', 'vector', 'VECTOR', self.algo, '10', 'TYPE', 'FLOAT32', 'DIM', len(X[0]), 'DISTANCE_METRIC', self.metric, 'INITIAL_CAP', len(X), 'BLOCK_SIZE', self.method_param['BLOCK_SIZE'], target_nodes='random')
except Exception as e:
    if 'Index already exists' not in str(e):
        raise

with regular module "redis", this works fine. When using RedisCluster module, the exception message is printed although the exception is caught.

github-actions[bot] commented 1 year ago

This issue is marked stale. It will be closed in 30 days if it is not updated.