Skip to content

Add missing exports for try_cast, bitwise_not, and label#1748

Open
veeceey wants to merge 1 commit intofastapi:mainfrom
veeceey:fix/export-try-cast-bitwise-not
Open

Add missing exports for try_cast, bitwise_not, and label#1748
veeceey wants to merge 1 commit intofastapi:mainfrom
veeceey:fix/export-try-cast-bitwise-not

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

Summary

Added missing exports for three functions that were defined in sqlmodel/sql/expression.py but not exported in sqlmodel/__init__.py, making them inaccessible to users.

Changes

Added exports for:

  • try_cast: SQL TRY_CAST operation for safe type casting (returns NULL on cast failure instead of raising an error)
  • bitwise_not: Bitwise NOT operation for integer columns
  • label: Create labeled expressions for query results

Why

These functions are fully implemented in sqlmodel/sql/expression.py but were missing from the public API. Users who needed these operations had to import directly from the internal module or use SQLAlchemy directly.

Test plan

  • ✅ Verified imports work: from sqlmodel import try_cast, bitwise_not, label
  • ✅ Existing tests pass
  • These functions are wrappers around SQLAlchemy functions with proper type hints

Related

This makes SQLModel's API more complete and consistent with SQLAlchemy's functionality.

Example usage after this change:

from sqlmodel import select, try_cast, Integer

# Safe casting that returns NULL on failure
statement = select(try_cast(column, Integer))

These functions were defined in sqlmodel/sql/expression.py but not exported
in sqlmodel/__init__.py, making them inaccessible to users.

Added exports for:
- try_cast: SQL TRY_CAST operation for safe type casting
- bitwise_not: Bitwise NOT operation
- label: Create labeled expressions

This makes the API more complete and consistent with SQLAlchemy's functionality.
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