Skip to content

Conversation

bsbodden
Copy link
Collaborator

No description provided.

@bsbodden bsbodden self-assigned this Sep 29, 2025
@bsbodden bsbodden requested a review from Copilot September 29, 2025 21:53
Copy link
Contributor

@Copilot 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 warning functionality to the EmbeddingsCache class to alert users when they attempt to use synchronous methods while only having an async Redis client configured. The warnings help guide users toward the appropriate async methods when sync operations may fail or behave unexpectedly.

  • Adds a class-level flag to prevent warning spam after the first occurrence
  • Implements warning logic in sync methods when only async client is available
  • Includes comprehensive test coverage for the warning behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
redisvl/extensions/cache/embeddings/embeddings.py Adds warning logic to sync methods (get_by_key, mget_by_keys, set, mset) when only async client is configured
tests/integration/test_embedcache_warnings.py Comprehensive test suite covering warning behavior in different client configurations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

owais and others added 7 commits September 29, 2025 17:13
…ed with get method of embedding cache when async redis client is provided
- Add concise warning messages when sync methods are called with async-only client
- Implement warning flag to prevent log spam (show warning only once per session)
- Add comprehensive test coverage for warning behavior
- Improve developer experience by providing clear guidance on method usage

The warnings now clearly indicate which async methods should be used instead
of sync methods when EmbeddingsCache is initialized with only an async client.
This helps prevent confusion when developers unintentionally use different
Redis connections than expected.
…ests

- Convert sync test functions to async when using async Redis clients
- Use _get_aredis_connection() for proper async client creation
- Add proper try/finally blocks to ensure client cleanup
- Fix 'Event loop is closed' errors in CI

The issue was that async Redis clients were being created in sync test
functions without proper event loop management. This caused cleanup
issues when the test finished.
- Replace direct Redis connection with redis_url fixture
- Use AsyncRedis.from_url() instead of RedisConnectionFactory
- Add proper try/finally blocks for client cleanup
- Follow established test patterns from test_embedcache.py

This fixes 'Event loop is closed' errors in CI by using the same
Docker container-based Redis connection that other tests use.
- Replace manual AsyncRedis.from_url() with async_client fixture
- Remove unnecessary AsyncRedis import
- Remove manual client cleanup (handled by fixture)
- Follows the pattern used by all other async tests in the codebase

This properly uses the conftest async_client fixture which handles
the Redis connection with proper context manager cleanup.
The test was failing in CI because sync methods were still trying to
create a Redis connection to localhost:6379 after logging the warning.
Now we mock _get_redis_client() to prevent actual connection attempts
while still testing the warning functionality.

This allows the test to verify warning behavior without requiring a
Redis connection for the sync methods that shouldn't be used anyway.
- Extract duplicated condition check into _should_warn_for_async_only() helper method
- Add pytest autouse fixture to reset warning flag before each test
- Improves code maintainability and test isolation

Co-authored-by: GitHub Copilot <[email protected]>
@bsbodden bsbodden force-pushed the bsb/sync-on-async-warnings branch from 5d9df94 to a2fb8f1 Compare September 30, 2025 00:18
@bsbodden bsbodden requested a review from Copilot September 30, 2025 00:31
Copy link
Contributor

@Copilot 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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bsbodden bsbodden merged commit 82ddb58 into main Sep 30, 2025
37 checks passed
@bsbodden bsbodden deleted the bsb/sync-on-async-warnings branch September 30, 2025 00:57
bsbodden added a commit that referenced this pull request Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant