-
Notifications
You must be signed in to change notification settings - Fork 16.3k
test: fix flaky MySQL integration test in test_update_v1_response #36176
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
Conversation
Code Review Agent Run #38e96eActionable Suggestions - 0Additional Suggestions - 2
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
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 fixes a flaky MySQL integration test in test_update_v1_response that intermittently fails due to MySQL's DATETIME type truncating microseconds to second-level precision.
Key changes:
- Added
time.sleep(1)to ensure timestamps differ at second-level precision - Modified timestamp comparison to normalize microseconds using
.replace(microsecond=0)for database-agnostic behavior
9dc6dbb to
4b9bfae
Compare
Split into two focused tests to properly handle MySQL's DATETIME second-level precision and the None → datetime transition: 1. test_update_sets_last_saved_at: Tests that last_saved_at gets set when previously None 2. test_update_changes_last_saved_at: Tests that last_saved_at changes when already set, using time.sleep(1) and .replace(microsecond=0) for MySQL precision handling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
4b9bfae to
4641b4e
Compare
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
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
|
|
||
| chart_to_update = db.session.query(Slice).get(pk) | ||
| chart_to_update.last_saved_at = datetime.now() | ||
| db.session.commit() |
Copilot
AI
Nov 20, 2025
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.
[nitpick] After setting last_saved_at = datetime.now() and committing, the Python object may still contain microseconds that were truncated by MySQL during the database write. To ensure last_saved_before contains the actual database value (without microseconds), consider querying the chart fresh after the commit:
chart_to_update = db.session.query(Slice).get(pk)
chart_to_update.last_saved_at = datetime.now()
db.session.commit()
# Refresh to get the database value with truncated microseconds
chart_to_update = db.session.query(Slice).get(pk)
last_saved_before = chart_to_update.last_saved_atThis makes the test more explicit and avoids relying on ORM refresh behavior.
| db.session.commit() | |
| db.session.commit() | |
| # Refresh to get the database value with truncated microseconds | |
| chart_to_update = db.session.query(Slice).get(pk) |
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.
addressed
After committing chart_to_update.last_saved_at, the in-memory Python object still contains microseconds, but MySQL's DATETIME(0) has truncated them in the database. This caused the test to compare against the wrong baseline value. Adding db.session.refresh() after commit ensures we capture the actual database value with MySQL's second-level precision before comparing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
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
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
betodealmeida
left a comment
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.
Thanks, this test was annoying!
…ache#36176) Co-authored-by: Claude <[email protected]>
…ache#36176) Co-authored-by: Claude <[email protected]>
SUMMARY
Fixes intermittent test failure in tests/integration_tests/charts/commands_tests.py::TestChartsUpdateCommand::test_update_v1_response that occurred on MySQL due to datetime precision handling with the error:
Root Cause:
Solution:
Split the original test into two focused, deterministic tests:
- Explicitly sets last_saved_at = None before update
- Verifies field gets populated after update
- No sleep needed
- Seeds last_saved_at = datetime.now() before update
- Sleeps 1 second to guarantee crossing second boundary for MySQL
- Uses .replace(microsecond=0) for database-agnostic comparison
- Verifies timestamp actually changed
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION