You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: correctly implement field projection with return_fields
- Move RETURN clause from query string to args list (fixes RediSearch syntax)
- Rename internal parameter from return_fields to projected_fields to avoid conflict with method name
- Return dictionaries instead of model instances when using field projection
- Add proper parsing for projected results that returns flat key-value pairs
- Add tests for both HashModel and JsonModel field projection
- Update validation to use model_fields instead of deprecated __fields__
This addresses all review comments from PR #633 and implements field projection correctly.
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
## Repository Overview
6
+
7
+
Redis OM Python is an object mapping library that provides declarative models for Redis data, built on Pydantic for validation and serialization. It supports both Redis Hash and JSON storage with automatic indexing via RediSearch.
8
+
9
+
## Development Commands
10
+
11
+
### Essential Commands
12
+
```bash
13
+
# Setup and dependencies
14
+
make install # Install all dependencies via Poetry
15
+
make redis # Start Redis Stack (6380) and Redis OSS (6381) containers
16
+
17
+
# Code generation (CRITICAL - always run after modifying async code)
18
+
make sync # Generate sync code from async using unasync
19
+
20
+
# Code quality
21
+
make format # Format with isort and black
22
+
make lint # Run flake8, mypy, and bandit
23
+
make test# Run full test suite against Redis Stack
24
+
make test_oss # Run tests against OSS Redis
25
+
26
+
# Individual test commands
27
+
poetry run pytest tests/test_hash_model.py::test_saves_model # Run specific test
28
+
poetry run pytest -n auto -vv ./tests/ ./tests_sync/ # Run all tests with parallelization
29
+
```
30
+
31
+
### Database Migrations
32
+
```bash
33
+
poetry run migrate # Run schema migrations for index changes
34
+
```
35
+
36
+
## Architecture and Code Organization
37
+
38
+
### Dual Async/Sync Architecture
39
+
**CRITICAL**: This codebase uses a unique dual-implementation approach:
40
+
-**Primary source**: `/aredis_om/` - All features implemented here first (async)
41
+
-**Generated code**: `/redis_om/` - Automatically generated sync version
42
+
-**Generation**: `make_sync.py` uses `unasync` to transform async → sync
43
+
44
+
**Development Rule**: NEVER directly edit files in `/redis_om/`. Always modify `/aredis_om/` and run `make sync`.
45
+
46
+
### Core Abstractions
47
+
48
+
#### Model Hierarchy
49
+
-`RedisModel` - Abstract base class
50
+
-`HashModel` - Stores data as Redis Hashes (simple key-value)
51
+
-`JsonModel` - Stores data as RedisJSON documents (nested structures)
52
+
-`EmbeddedJsonModel` - For nested JSON models without separate storage
53
+
54
+
#### Query System
55
+
Expression-based queries using Django ORM-like syntax:
56
+
```python
57
+
results =await Customer.find(
58
+
(Customer.age >18) & (Customer.country =="US")
59
+
).all()
60
+
```
61
+
62
+
#### Field System
63
+
Built on Pydantic fields with Redis-specific extensions:
64
+
-`Field(index=True)` - Create secondary index
65
+
-`Field(full_text_search=True)` - Enable text search
66
+
-`VectorField` - For similarity search with embeddings
67
+
68
+
### Key Implementation Patterns
69
+
70
+
1.**Connection Management**: Uses `get_redis_connection()` from `connections.py`
71
+
2.**Index Management**: Automatic RediSearch index creation via migration system
72
+
3.**Query Resolution**: `QueryResolver` class handles expression tree → RediSearch query conversion
73
+
4.**Type Validation**: All models use Pydantic v2 for validation
74
+
75
+
## Important Constraints
76
+
77
+
1.**Database 0 Only**: RediSearch indexes only work in Redis database 0
78
+
2.**Module Requirements**: Advanced features require Redis Stack (RediSearch + RedisJSON)
79
+
3.**Python Versions**: Supports Python 3.8-3.13, test across versions with tox
80
+
4.**Async Testing**: Tests use `pytest-asyncio` with `asyncio_mode = strict`
81
+
82
+
## Testing Approach
83
+
84
+
- Separate test directories: `/tests/` (async) and `/tests_sync/` (sync)
85
+
- Docker Compose provides test Redis instances
86
+
- Use fixtures from `conftest.py` for Redis connections
87
+
- Mark tests requiring Redis modules with appropriate decorators
0 commit comments