-
Notifications
You must be signed in to change notification settings - Fork 122
Fix timestamp handling #711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Convert numerical values to and from datetime objects. Includes a new data migration feature and a migration to convert numerical TAG fields to NUMERIC. Moves OM CLI commands into a new top-level `om` command while preserving backwards compat for old `migrate` command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements timestamp handling for datetime fields in Redis-OM Python by converting datetime objects to Unix timestamps for storage, enabling proper NUMERIC indexing in RediSearch. It includes a comprehensive data migration system and moves CLI commands under a unified om
command structure.
- Convert datetime fields from string/object storage to Unix timestamp storage for proper indexing
- Add data migration framework with dependency management and rollback support
- Create unified
om
CLI interface while maintaining backward compatibility
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
tests/test_datetime_fix.py | Tests datetime timestamp conversion for HashModel and JsonModel |
tests/test_datetime_date_fix.py | Tests date field conversion to timestamps |
tests/test_data_migrations.py | Comprehensive test suite for the data migration system |
pyproject.toml | Adds new om CLI entry point with backward compatibility |
docs/migrations.md | Complete documentation for schema and data migration systems |
aredis_om/util.py | Extends NUMERIC_TYPES to include datetime types |
aredis_om/model/model.py | Core timestamp conversion logic and model save/get modifications |
aredis_om/model/migrations/datetime_migration.py | Built-in migration to convert existing datetime data |
aredis_om/model/migrations/data_migrator.py | Framework for managing data migrations |
aredis_om/model/cli/migrate_data.py | CLI commands for data migration operations |
aredis_om/cli/main.py | Unified CLI entry point |
aredis_om/cli/init.py | CLI package initialization |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Replace nested exception blocks with cleaner helper functions to improve maintainability and debuggability. Eliminates broad exception catching that could mask real bugs while preserving datetime conversion functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Remove duplicate 'om' command prefixes in migration documentation. Commands should be 'om migrate-data' not 'om om migrate-data'. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
The refactored datetime conversion helper functions introduced subtle timezone handling differences that broke model equality comparisons in tests. Restoring the original working implementation to maintain compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add missing importlib.util import in data_migrator.py - Use type(None) instead of string comparison for type checking - Remove debug print statements from test files (security concern) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add missing importlib.util import in data_migrator.py - Fix type checking with proper noqa for E721 - Remove debug print statements from tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
# Get model data and apply transformations in the correct order | ||
data = self.model_dump() | ||
# Convert datetime objects to timestamps for proper indexing | ||
data = convert_datetime_to_timestamp(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows users to use normal type annotations for datetime fields, instead of a special field type we provide, even if it's messier "on the backend."
Convert numerical values to and from datetime objects. Includes a new data migration feature and a migration to convert numerical TAG fields to NUMERIC.
Also, moves OM CLI commands into a new top-level
om
command while preserving backwards compatibility for the oldmigrate
command.