-
Notifications
You must be signed in to change notification settings - Fork 124
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description
FindQuery objects don't support chaining .find() calls, which is a common pattern users expect from ORMs like Django. This leads to AttributeError and can be confusing.
Steps to Reproduce
from aredis_om import HashModel, Field, Migrator
import asyncio
class Product(HashModel, index=True):
name: str = Field(index=True)
category: str = Field(index=True)
price: float = Field(index=True)
async def main():
await Migrator().run()
# This pattern feels natural but doesn't work:
query = Product.find(Product.category == "electronics")
query = query.find(Product.price > 100) # ❌ AttributeError
results = await query.all()
asyncio.run(main())Error
AttributeError: 'FindQuery' object has no attribute 'find'
Expected Behavior
Users familiar with Django or SQLAlchemy expect to be able to chain filter calls:
# Django-style (what users expect):
query = Product.find(Product.category == "electronics")
query = query.find(Product.price > 100)
query = query.find(Product.in_stock > 0)
results = await query.all()Current Workarounds
1. Use & operator to combine expressions
results = await Product.find(
(Product.category == "electronics") & (Product.price > 100)
).all()2. Pass multiple expressions to find()
results = await Product.find(
Product.category == "electronics",
Product.price > 100
).all()3. Build a list of filters and unpack
filters = []
if category:
filters.append(Product.category == category)
if min_price:
filters.append(Product.price >= min_price)
if filters:
results = await Product.find(*filters).all()
else:
results = await Product.find().all()Proposal
Either:
- Add
.find()method toFindQuery- Allow chaining like Django's QuerySet - Add
.filter()method toFindQuery- Alternative name that adds conditions - Document the correct patterns prominently - If chaining isn't supported, make the correct patterns very visible in docs
Impact
This is a common stumbling block when building dynamic queries (e.g., in API endpoints with optional filters). The workarounds work but aren't discoverable without reading source code or hitting the error.
Environment
- redis-om version: 1.0.0 (current main branch)
- Python version: 3.12
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request