Fix tournament and match timestamps defaulting to Unix epoch - #22
Merged
Merged
Conversation
Copilot created this pull request from a session on behalf of
Horus0305
June 3, 2026 10:05
View session
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR prevents tournament and match history timestamps from defaulting to Unix epoch (1970-01-01) by explicitly setting UTC timestamps at write-time, adding safer timestamp parsing during data restore, and introducing a one-off migration script + documentation to repair existing bad rows.
Changes:
- Explicitly sets
timestamp=datetime.utcnow()when persisting newTournamentHistoryandMatchHistoryrecords. - Adds
restore_data.py::_dt_with_fallback()to ensure imports never writeNonetimestamps when parsing fails. - Adds
fix_tournament_timestamps.pyplusTOURNAMENT_TIMESTAMP_FIX.mdto retroactively repair NULL/epoch timestamps.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
TOURNAMENT_TIMESTAMP_FIX.md |
Documents the root cause, remediation steps, and verification commands for fixing timestamps. |
CricketGame/restore_data.py |
Adds timestamp parsing fallback to avoid NULL timestamps during data import. |
CricketGame/fix_tournament_timestamps.py |
New migration script to repair NULL/epoch tournament timestamps (and targeted IDs). |
CricketGame/backend/realtime/tournament.py |
Sets tournament history timestamps explicitly at persistence time. |
CricketGame/backend/realtime/match/match_persistence.py |
Sets match history timestamps explicitly at persistence time. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+51
to
+52
| engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False}) | ||
| Session = sessionmaker(bind=engine) |
Comment on lines
+95
to
+109
| for tid in PROBLEMATIC_IDS: | ||
| tournament = db.query(TournamentHistory).filter( | ||
| TournamentHistory.tournament_id == tid | ||
| ).first() | ||
| if tournament: | ||
| old_ts = tournament.timestamp | ||
| tournament.timestamp = datetime.utcnow() | ||
| db.commit() | ||
| print(f" ✓ {tid}: Updated from {old_ts} to {tournament.timestamp}") | ||
| fixed_count += 1 | ||
| else: | ||
| print(f" - {tid}: Not found in database") | ||
|
|
||
| print(f" Fixed {fixed_count} specific tournament IDs") | ||
| print() |
Comment on lines
+114
to
+127
| # Find NULL timestamps | ||
| null_count = 0 | ||
| null_tournaments = db.query(TournamentHistory).filter( | ||
| TournamentHistory.timestamp == None | ||
| ).all() | ||
|
|
||
| for tournament in null_tournaments: | ||
| tournament.timestamp = datetime.utcnow() | ||
| db.commit() | ||
| print(f" ✓ {tournament.tournament_id}: Updated from NULL to {tournament.timestamp}") | ||
| null_count += 1 | ||
|
|
||
| print(f" Fixed {null_count} tournaments with NULL timestamps") | ||
| print() |
Comment on lines
+129
to
+143
| # Find epoch (01/01/1970) timestamps | ||
| epoch_count = 0 | ||
| all_tournaments = db.query(TournamentHistory).all() | ||
|
|
||
| for tournament in all_tournaments: | ||
| if tournament.timestamp and tournament.timestamp.year == 1970 and \ | ||
| tournament.timestamp.month == 1 and tournament.timestamp.day == 1: | ||
| old_ts = tournament.timestamp | ||
| tournament.timestamp = datetime.utcnow() | ||
| db.commit() | ||
| print(f" ✓ {tournament.tournament_id}: Updated from {old_ts} to {tournament.timestamp}") | ||
| epoch_count += 1 | ||
|
|
||
| print(f" Fixed {epoch_count} tournaments with epoch (01/01/1970) timestamps") | ||
| print() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tournaments and matches were being stored with 01/01/1970 timestamps when timestamp data was missing or unparseable, due to NULL values cascading to database epoch defaults.
Changes
Explicit timestamp initialization
backend/realtime/tournament.py: Settimestamp=datetime.utcnow()when creatingTournamentHistoryrecords (previously relied on unreliableserver_default)backend/realtime/match/match_persistence.py: Settimestamp=datetime.utcnow()when creatingMatchHistoryrecordsImport robustness
restore_data.py: Added_dt_with_fallback()helper that returns current UTC time instead of None when timestamp parsing failsData migration
fix_tournament_timestamps.py: New script to retroactively fix existing records with NULL or epoch timestampsDocumentation
TOURNAMENT_TIMESTAMP_FIX.md: Comprehensive guide for applying the migration and understanding the fixExample
To fix existing records in the database, run:
python fix_tournament_timestamps.py