From 952fa53213f9f788d5236b331816b5363a3dbe84 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sat, 22 Sep 2018 03:01:32 +0300 Subject: [PATCH] Update migration FAQ // Add FSMStorageProxy --- docs/source/migration_1_to_2.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/source/migration_1_to_2.rst b/docs/source/migration_1_to_2.rst index 1f300506..b5b6cde8 100644 --- a/docs/source/migration_1_to_2.rst +++ b/docs/source/migration_1_to_2.rst @@ -15,11 +15,13 @@ Changelog - Allowed to customize command prefix in CommandsFilter; - Implemented mechanism of passing results from filters (as dicts) as kwargs in handlers (like fixtures in pytest); - Implemented states group feature; +- Implemented FSM storage's proxy; - Changed files uploading mechanism; - Implemented I18n Middleware; - Errors handlers now should accept only two arguments (current update and exception); - Used `aiohttp_socks` instead of `aiosocksy` for Socks4/5 proxy; - `types.ContentType` was divided to `types.ContentType` and `types.ContentTypes`; +- Allowed to use rapidjson instead of ujson/json; - (**in process**) Implemented utils for Telegram Passport; - (**in process**) Webhook security improvements; @@ -133,6 +135,26 @@ Writing states group: After that you can use states as `UserForm.name` and etc. +FSM storage's proxy +------------------- +Now `Dispatcher.current_context()` can't be used as context-manager. + +Implemented `FSMContext.proxy()` method which returns asynchronous `FSMContextProxy` context manager and can be used for more simply getting data from the storage. + +`FSMContextProxy` load all user-related data on initialization and dump it to the storage when proxy is closing if any part of the data was changed. + + +Usage: + +.. code-block:: python + + @dp.message_handler(commands=['click']) + async def cmd_start(message: types.Message, state: FSMContext): + async with state.proxy() as proxy: # proxy: FSMContextProxy + proxy.setdefault('counter', 0) + proxy['counter'] += 1 + return await message.reply(f"Counter: {proxy['counter']}") + File uploading mechanism ------------------------