You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2025/11/19 00:59:41 UTC

(superset) 01/01: test: fix flaky MySQL test in test_update_v1_response

This is an automated email from the ASF dual-hosted git repository.

jli pushed a commit to branch fix-flakey-test-mysql-integration
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 9dc6dbb776b7c70eb76d792064810d67d318f1d9
Author: Joe Li <jo...@preset.io>
AuthorDate: Tue Nov 18 16:58:30 2025 -0800

    test: fix flaky MySQL test in test_update_v1_response
    
    Add time.sleep(1) and normalize timestamps with .replace(microsecond=0)
    to handle MySQL's second-level datetime precision. This prevents test
    failures when the test executes within the same second.
    
    - MySQL DATETIME defaults to second precision, truncating microseconds
    - Pattern matches tests/integration_tests/dashboards/dao_tests.py
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-Authored-By: Claude <no...@anthropic.com>
---
 tests/integration_tests/charts/commands_tests.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tests/integration_tests/charts/commands_tests.py b/tests/integration_tests/charts/commands_tests.py
index a0608df35d..3352d52311 100644
--- a/tests/integration_tests/charts/commands_tests.py
+++ b/tests/integration_tests/charts/commands_tests.py
@@ -14,6 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import time
 from unittest.mock import patch
 
 import pytest
@@ -383,9 +384,15 @@ class TestChartsUpdateCommand(SupersetTestCase):
         }
         command = UpdateChartCommand(model_id, json_obj)
         last_saved_before = db.session.query(Slice).get(pk).last_saved_at
+        # Sleep to ensure timestamp differs at MySQL's second precision
+        # MySQL DATETIME defaults to second-level precision, truncating microseconds
+        time.sleep(1)
         command.run()
         chart = db.session.query(Slice).get(pk)
-        assert chart.last_saved_at != last_saved_before
+        # Normalize microseconds for database-agnostic comparison
+        assert chart.last_saved_at.replace(microsecond=0) != last_saved_before.replace(
+            microsecond=0
+        )
         assert chart.last_saved_by == user
 
     @patch("superset.utils.core.g")