Skip to content

0.17.0

Choose a tag to compare

@igorbenav igorbenav released this 25 Sep 13:13
· 212 commits to main since this release
1b331cc

0.17.0 Summary

Fixed

  • Pydantic Relationship Fields Issue by @doubledare704
    • Fixed get_multi returning boolean values for Pydantic relationship fields when select schema is provided
    • Resolved cartesian product issues when including relationship fields in schemas
    • Enhanced test coverage with comprehensive SQL verification
  • Delete Methods Filtering & Typing by @doubledare704
    • Added missing filter support for delete operations
    • Improved type annotations for delete methods
    • Enhanced type safety for delete operations
  • Dynamic Filter Parsing by @luminosoda
    • Fixed parsing issue with filter operators containing double underscores
    • Correctly handles complex filter operations like field__gte, field__lt
    • Improved robustness of dynamic filter processing

Added

  • Joined Model Filtering for Automatic Endpoints by @doubledare704
    • Support for dot notation in filter configurations (e.g., company.name)
    • Automatic detection and handling of relationship-based filters
    • Enhanced FilterConfig to validate and parse joined model filters
    • Comprehensive filtering across related models in CRUD endpoints

Improved

  • Test Infrastructure Enhancement by @doubledare704
    • Refactored test suite to eliminate pytest warnings
    • Enhanced test coverage with SQL-level verification
    • Better integration with existing test patterns
    • More descriptive test naming conventions

Documentation Updates

  • Joined Model Filtering Guide with comprehensive examples and usage patterns
  • Enhanced Endpoint Documentation with detailed filtering examples
  • Improved Test Documentation with better patterns and conventions

Breaking Changes

⚠️ None - This release maintains full backward compatibility with 0.16.x

Details


Fixed Pydantic Relationship Fields Issue

Description

Resolved a critical bug where get_multi would return boolean values instead of proper data when Pydantic schemas included relationship fields. This issue was caused by cartesian product queries that resulted in incorrect data serialization.

Changes

  • Relationship Field Exclusion: Automatically excludes relationship fields from SELECT statements to prevent cartesian products
  • Schema Validation Fix: Ensures return_as_model=True works correctly with relationship schemas
  • SQL Query Optimization: Prevents unnecessary joins that caused performance issues

Issue Resolution

This fix resolves GitHub issue #199 where users experienced:

  • Boolean values instead of expected data in API responses
  • Performance degradation due to cartesian product queries
  • Inconsistent behavior when using relationship fields in select schemas
# Before: Would cause cartesian product and return boolean values
class UserSchema(BaseModel):
    name: str
    company: Optional[CompanySchema] = None

# After: Properly handles relationship fields without cartesian products
users = await crud_users.get_multi(
    db=db,
    schema_to_select=UserSchema,
    return_as_model=True
)

Joined Model Filtering for Automatic Endpoints

Description

Introduced powerful filtering capabilities across related models using dot notation, enabling complex queries on joined data directly through API endpoints.

Changes

  • Dot Notation Support: Filter by related model fields using related_model.field syntax
  • Automatic Join Detection: FastCRUD automatically detects when joins are needed
  • FilterConfig Enhancement: Extended to validate and parse relationship paths
  • Endpoint Integration: Seamless integration with existing CRUD endpoints

Usage Examples

Basic Joined Filtering:

from fastcrud import FilterConfig, crud_router

# Filter users by company name
user_router = crud_router(
    session=async_session,
    model=User,
    filter_config=FilterConfig(
        company__name=str,  # Filter by company.name
        company__industry=str,  # Filter by company.industry
    ),
)

API Usage:

# Filter users working in Technology companies
GET /users?company__name=TechCorp&company__industry=Technology

# Combined with existing filters
GET /users?name=Alice&company__name=TechCorp&limit=10

Benefits

  • Flexible Querying: Filter across multiple related models without complex query building
  • Performance Optimized: Automatic join optimization prevents unnecessary queries
  • Type Safe: Full type checking and validation for relationship paths
  • API Friendly: Clean REST API interface for complex filtering

Enhanced Delete Methods with Filtering

Description

Fixed missing filter support in delete operations and improved type annotations for better development experience and type safety.

Changes

  • Delete Filters: Added comprehensive filter support for delete and db_delete methods
  • Type Annotations: Enhanced type hints for better IDE support and static analysis
  • Consistency: Aligned delete method signatures with other CRUD operations

Usage Example

# Delete with filters - now supported
deleted_count = await crud_items.delete(
    db=db,
    filters={"category": "deprecated", "price__lt": 10}
)

# Type-safe delete operations
result: int = await crud_items.db_delete(
    db=db, 
    filters={"status": "inactive"}
)

Issue Resolution

Resolves GitHub issue #147 by providing:

  • Consistent filtering API across all CRUD operations
  • Better type safety for delete operations
  • Enhanced developer experience with proper type hints

Dynamic Filter Parsing Fix

Description

Fixed a parsing issue in dynamic filters where operators containing double underscores (like field__gte) were not handled correctly, causing filter validation failures.

Changes

  • Operator Parsing: Correctly extracts field names from complex operators
  • Robustness: Handles edge cases in filter key parsing
  • Compatibility: Maintains backward compatibility with existing filter patterns

Issue Resolution

Resolves GitHub issue #248 by ensuring:

  • Complex filter operators work correctly
  • Field type validation applies to the correct field name
  • No breaking changes to existing filter syntax
# Before: Would fail validation
GET /items?price__gte=100&date__lt=2024-01-01

# After: Works correctly with proper field validation
GET /items?price__gte=100&date__lt=2024-01-01

What's Changed

New Contributors

Full Changelog: v0.16.0...v0.17.0