Check destiny in case of no with_destiny (#776)

* cehck if destiny is default

* Test testiny check

* reformat
This commit is contained in:
Andrey Tikhonov 2021-12-12 18:54:01 +03:00 committed by GitHub
parent 9ec689b562
commit 1357a7a91b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 6 deletions

View file

@ -6,7 +6,7 @@ from aioredis import ConnectionPool, Redis
from aiogram import Bot
from aiogram.dispatcher.fsm.state import State
from aiogram.dispatcher.fsm.storage.base import BaseStorage, StateType, StorageKey
from aiogram.dispatcher.fsm.storage.base import DEFAULT_DESTINY, BaseStorage, StateType, StorageKey
DEFAULT_REDIS_LOCK_KWARGS = {"timeout": 60}
@ -62,6 +62,13 @@ class DefaultKeyBuilder(KeyBuilder):
parts.extend([str(key.chat_id), str(key.user_id)])
if self.with_destiny:
parts.append(key.destiny)
elif key.destiny != DEFAULT_DESTINY:
raise ValueError(
"Redis key builder is not configured to use key destiny other the default.\n"
"\n"
"Probably, you should set `with_destiny=True` in for DefaultKeyBuilder.\n"
"E.g: `RedisStorage(redis, key_builder=DefaultKeyBuilder(with_destiny=True))`"
)
parts.append(part)
return self.separator.join(parts)