Skip to content

[#1431 , #1445 , #1594] feature: Add get_value method to MongoDB and Redis FSM storages#1669

Closed
Vadim-Khristenko wants to merge 4 commits intoaiogram:dev-3.xfrom
Vadim-Khristenko:add-feature-fsm
Closed

[#1431 , #1445 , #1594] feature: Add get_value method to MongoDB and Redis FSM storages#1669
Vadim-Khristenko wants to merge 4 commits intoaiogram:dev-3.xfrom
Vadim-Khristenko:add-feature-fsm

Conversation

@Vadim-Khristenko
Copy link
Contributor

Description

Added get_value method to MongoDB and Redis FSM storages to retrieve individual values from stored user data. This completes the implementation across all storage backends.

For MongoDB, the implementation uses projection queries to optimize performance when retrieving single values from large data objects.

Fixes #1431
Supersedes inactive PR #1445 (no updates since June 18, 2024)
Complements PR #1594 (which added the method to MemoryStorage and Scenes)

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Comprehensive MongoDB-specific tests including projection optimization verification
  • Basic Redis functionality tests (samples available at this gist) - can be added to the main test suite if needed
  • Integration with existing storage test cases
  • Default value handling and edge cases

Test Configuration:

  • Operating System: Ubuntu 20.04.6 LTS (GitHub Codespace)
  • Python version: 3.12.9 (Conda)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature works
  • New and existing unit tests pass locally with my changes

Implement get_value method for MongoStorage that retrieves
individual values from storage data using MongoDB projections.

Add comprehensive test coverage for the new method.
@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Apr 7, 2025
@github-actions
Copy link

github-actions bot commented Apr 7, 2025

✔️ Changelog found.

Thank you for adding a description of the changes

@Vadim-Khristenko Vadim-Khristenko marked this pull request as ready for review April 7, 2025 18:05
@JrooTJunior JrooTJunior requested a review from Copilot April 26, 2025 13:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new feature method, get_value, to MongoDB and Redis FSM storages to enable efficient retrieval of individual user data values using projection queries for MongoDB.

  • Added tests for the get_value method in the MongoDB test suite
  • Introduced get_value overloads and its implementation in Redis storage
  • Implemented get_value in MongoDB storage with projection support for optimized data retrieval

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
tests/test_fsm/storage/test_mongo.py Added comprehensive tests for get_value behavior
aiogram/fsm/storage/redis.py Introduced overloaded get_value with implementation
aiogram/fsm/storage/mongo.py Added get_value with projection support for MongoDB
Files not reviewed (1)
  • CHANGES/1669.feature.rst: Language not supported

Copy link
Member

@JrooTJunior JrooTJunior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any important changes that add or improve anything, so why should these changes be accepted?

async def get_value(self, storage_key: StorageKey, dict_key: str, default: Any) -> Any: ...

async def get_value(
self, storage_key: StorageKey, dict_key: str, default: Optional[Any] = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to override this method in the Redis Storage because the base implementation is the same as you have added.

async def get_value(self, storage_key: StorageKey, dict_key: str, default: Any) -> Any: ...

async def get_value(
self, storage_key: StorageKey, dict_key: str, default: Optional[Any] = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually what is the difference with the original implementation in the base method?

Is the same as get_data + get_value, so it is not needed to be overriden

@Vadim-Khristenko
Copy link
Contributor Author

I have decided to close this pull request due to its lack of necessity and relevance. I sincerely apologize for wasting your time, @JrooTJunior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Issue or PR for stable 3.x version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add function get_value to FSMContext

2 participants