FastCRUD 0.21.0 Release Notes
Important
Security Update: This release addresses critical security vulnerabilities in dependencies. All users should upgrade immediately.
Note
Python 3.9 Dropped: Minimum Python version is now 3.10. Python 3.9 reached end-of-life in October 2025.
FastCRUD 0.21.0 introduces automatic relationship detection, eliminating the need to manually configure joins for most use cases. Simply set include_relationships=True on your router and FastCRUD handles the rest.
Documentation:
- Auto-Detecting Relationships - Complete guide to relationship auto-detection
- Including Relationships in Endpoints - Using relationships with
crud_router - One-to-Many Relationships - Handling collections with
nested_limit
Summary
What's New for Users:
- Automatic Relationship Detection: Auto-detect and include SQLAlchemy relationships without manual
JoinConfig - Safe One-to-Many Defaults: One-to-many relationships excluded by default to prevent unbounded data fetching
- SQL-Level Limiting: New
nested_limitparameter uses window functions for efficient database-level limiting - Selective Relationship Inclusion: Include specific relationships by name (e.g.,
["tier", "department"]) - Bidirectional FK Detection: Foreign keys detected on either side of a relationship
- Python 3.13 Support: Official support for the latest Python version
Security Fixes:
- CVE-2025-62611: aiomysql arbitrary file access vulnerability (upgraded to 0.3.0+)
- CVE-2026-22701: filelock TOCTOU symlink vulnerability (upgraded to 3.20.3+)
New Features
Automatic Relationship Detection
Docs: Auto-Detecting Relationships | Including Relationships in Endpoints
FastCRUD can now automatically detect and include SQLAlchemy relationships defined on your models. No more manual JoinConfig for standard relationships.
With crud_router:
from fastcrud import crud_router
router = crud_router(
session=get_db,
model=Book,
create_schema=BookCreate,
update_schema=BookUpdate,
select_schema=BookWithAuthor, # Schema includes relationship fields
include_relationships=True, # Auto-detect and include relationships
)Response automatically includes related data:
{
"data": [
{
"id": 1,
"title": "The Great Gatsby",
"author": {
"id": 1,
"name": "F. Scott Fitzgerald"
}
}
]
}With FastCRUD directly:
# Auto-detect all relationships
user = await user_crud.get_joined(
db=db,
auto_detect_relationships=True,
nest_joins=True,
id=1,
)
# Or for multiple records
users = await user_crud.get_multi_joined(
db=db,
auto_detect_relationships=True,
nest_joins=True,
)Selective Relationship Inclusion
Instead of including all relationships, specify exactly which ones you need:
# Only include specific relationships
router = crud_router(
session=get_db,
model=User,
include_relationships=["tier", "department"], # Only these two
)
# Or with FastCRUD directly
user = await user_crud.get_joined(
db=db,
auto_detect_relationships=["tier"], # Only tier, not all relationships
id=1,
)Benefits:
- Performance: Only fetch the relationships you need
- Control: Explicit about what data is included
- Validation: Invalid relationship names raise helpful errors
# Invalid relationship name raises ValueError
user = await user_crud.get_joined(
db=db,
auto_detect_relationships=["nonexistent"],
id=1,
)
# ValueError: Invalid relationship names: {'nonexistent'}.
# Available relationships on User: {'tier', 'department', 'tasks'}Safe Defaults for One-to-Many Relationships
One-to-many relationships are excluded by default when using auto_detect_relationships=True. This prevents accidental performance issues from unbounded JOINs.
Why? A query returning 100 users with 50 posts each produces 5,000 rows from the database. The default prevents this surprise.
To include one-to-many relationships:
# Option 1: Explicitly enable
user = await user_crud.get_joined(
db=db,
auto_detect_relationships=True,
include_one_to_many=True, # Opt-in to one-to-many
nest_joins=True,
id=1,
)
# Option 2: List specific relationships (bypasses exclusion)
user = await user_crud.get_joined(
db=db,
auto_detect_relationships=["tier", "posts"], # "posts" is one-to-many
nest_joins=True,
id=1,
)
# Option 3: Use include_one_to_many with crud_router
router = crud_router(
session=get_db,
model=Author,
include_relationships=True,
include_one_to_many=True,
)SQL-Level Limiting with Window Functions
For one-to-many relationships, use nested_limit to limit results at the database level using efficient window functions:
from fastcrud import JoinConfig
# Limit to 10 articles per author using SQL window functions
author = await author_crud.get_joined(
db=db,
joins_config=[
JoinConfig(
model=Article,
join_on=Author.id == Article.author_id,
relationship_type="one-to-many",
nested_limit=10, # ROW_NUMBER() OVER (PARTITION BY author_id)
)
],
nest_joins=True,
id=1,
)How it works:
- Main query fetches parent records normally
- Separate query uses
ROW_NUMBER() OVER (PARTITION BY ...)for one-to-many data - Results are merged efficiently in Python
Bidirectional Foreign Key Detection
Auto-detection works regardless of which side has the foreign key:
# Forward: FK on Article pointing to Author
article = await article_crud.get_joined(
db=db,
join_model=Author, # Detects: Article.author_id -> Author.id
id=1,
)
# Reverse: Joining from Author to Article (FK is on Article side)
author = await author_crud.get_joined(
db=db,
join_model=Article, # Also works! Finds FK on Article side
id=1,
)Automatic Aliasing
When a model has multiple relationships to the same table, FastCRUD automatically creates aliases:
class Task(Base):
creator_id = Column(ForeignKey("users.id"))
assignee_id = Column(ForeignKey("users.id"))
creator = relationship("User", foreign_keys=[creator_id])
assignee = relationship("User", foreign_keys=[assignee_id])
# Both relationships auto-detected with proper aliases
task = await task_crud.get_joined(
db=db,
auto_detect_relationships=True,
nest_joins=True,
id=1,
)
# Returns: {"id": 1, "creator": {...}, "assignee": {...}}Graceful Fallback
Models without relationships work without errors:
# Model with no relationships
result = await simple_crud.get_joined(
db=db,
auto_detect_relationships=True,
id=1,
)
# Works fine - returns simple record without joinsSecurity Updates
CVE-2025-62611 - aiomysql Arbitrary File Access
Severity: High
aiomysql versions prior to 0.3.0 did not validate client-side settings before sending local files to MySQL server, allowing a malicious MySQL server to obtain arbitrary files from the client.
Fix: Upgraded aiomysql to 0.3.0+
CVE-2026-22701 - filelock TOCTOU Vulnerability
Severity: Moderate
filelock versions prior to 3.20.3 had a Time-of-Check-Time-of-Use (TOCTOU) race condition in SoftFileLock that could allow local attackers to corrupt or truncate arbitrary files through symlink attacks.
Fix: Upgraded filelock to 3.20.3+
Breaking Changes
Python 3.9 No Longer Supported
Minimum Python version is now 3.10.
Python 3.9 reached end-of-life in October 2025. This release drops support for two reasons:
- Security dependencies: filelock 3.20.3+ requires Python 3.10+
- Modern type hints: Codebase now uses
X | Yunion syntax instead ofOptional[X]andUnion[X, Y]
Migration: Update your Python version to 3.10 or higher.
aiomysql local_infile Parameter (Dev Dependency)
If you use MySQL with LOAD DATA LOCAL INFILE in your tests or development, note that aiomysql 0.3.0 changed how this is configured:
# Before (no longer works)
conn = await aiomysql.connect(client_flag=CLIENT.LOCAL_FILES)
# After (required)
conn = await aiomysql.connect(local_infile=True)This only affects the dev dependency used for testing - it does not affect FastCRUD's public API.
Bug Fixes
- Endpoint Validation: EndpointCreator now verifies that a model has a valid
join_configbefore attempting joined operations, preventing confusing errors
Improved
- Modern Type Hints: Codebase updated to use Python 3.10+ type hint syntax:
list[X]instead ofList[X]dict[K, V]instead ofDict[K, V]X | Noneinstead ofOptional[X]X | Yinstead ofUnion[X, Y]
- Test Coverage: Added comprehensive tests for one-to-many relationship handling
- Documentation: Enhanced joins documentation with auto-detection examples and best practices
What's Changed
- Add opt-in auto-detection of SqlAlchemy relationships by @F1nnM in #310
- one_to_many tests by @LucasQR in #312
- upgrade packages (security fixes) by @igorbenav in #313
New Contributors
Issues Closed
- #24 - Add Relationship Support in Auto Generated Endpoints (partially addressed)
Full Changelog: v0.20.1...v0.21.0