Skip to content

test_datetime fails with a --forever argument #120782

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

Closed
Eclips4 opened this issue Jun 20, 2024 · 4 comments
Closed

test_datetime fails with a --forever argument #120782

Eclips4 opened this issue Jun 20, 2024 · 4 comments
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@Eclips4
Copy link
Member

Eclips4 commented Jun 20, 2024

Bug report

Bug description:

Output:

...many lines
test_resolution_info (test.datetimetester.TestTime_Fast.test_resolution_info) ... FAIL

======================================================================
FAIL: test_resolution_info (test.datetimetester.TestTime_Fast.test_resolution_info)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/admin/Projects/cpython/Lib/test/datetimetester.py", line 3685, in test_resolution_info
    self.assertIsInstance(self.theclass.max, self.theclass)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: -1224 is not an instance of <class 'datetime.time'>

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

@Eclips4 Eclips4 added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Jun 20, 2024
@JelleZijlstra
Copy link
Member

A more detailed repro case:

$ ./python.exe -m test test_datetime -v -m test_utctimetuple --forever
== CPython 3.14.0a0 (heads/fixsymtable:35f8855402a, Jun 19 2024, 22:18:17) [Clang 15.0.0 (clang-1500.3.9.4)]
== macOS-14.4.1-arm64-arm-64bit-Mach-O little-endian
== Python build: debug
== cwd: /Users/jelle/py/cpython/build/test_python_worker_88684æ
== CPU count: 8
== encodings: locale=UTF-8 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 2286005019
0:00:00 load avg: 1.69 Run tests sequentially in a single process
0:00:00 load avg: 1.69 [  1] test_datetime
test_utctimetuple (test.datetimetester.TestDateTimeTZ_Pure.test_utctimetuple) ... ok
test_utctimetuple (test.datetimetester.TestDateTimeTZ_Fast.test_utctimetuple) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK
0:00:00 load avg: 1.69 [  2] test_datetime
test_utctimetuple (test.datetimetester.TestDateTimeTZ_Pure.test_utctimetuple) ... ok
test_utctimetuple (test.datetimetester.TestDateTimeTZ_Fast.test_utctimetuple) ... ERROR

======================================================================
ERROR: test_utctimetuple (test.datetimetester.TestDateTimeTZ_Fast.test_utctimetuple)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jelle/py/cpython/Lib/test/datetimetester.py", line 4945, in test_utctimetuple
    dtz = d.replace(tzinfo=tz)
TypeError: tzinfo argument must be None or of a tzinfo subclass, not type 'datetime.timedelta'

----------------------------------------------------------------------
Ran 2 tests in 0.005s

FAILED (errors=1)
test test_datetime failed

== Tests result: FAILURE ==

1 test failed:
    test_datetime

1 test OK.

Total duration: 95 ms
Total tests: run=4 (filtered)
Total test files: run=2 (filtered) failed=1
Result: FAILURE

I added a print([timezone.min, timezone.utc, timezone.max]) right before the failure. It should output [datetime.timezone(datetime.timedelta(days=-1, seconds=60)), datetime.timezone.utc, datetime.timezone(datetime.timedelta(seconds=86340))], but I get various other things, apparently randomly:

  • [datetime.timezone(datetime.timedelta(days=-1, seconds=60)), datetime.timezone.utc, 9999]
  • [datetime.timedelta(seconds=86340), datetime.timezone.utc, 9999]
  • [datetime.timedelta(seconds=86340), datetime.timezone.utc, datetime.timezone(datetime.timedelta(seconds=86340))]

This suggests the timezone class's __dict__ is somehow getting corrupted.

@JelleZijlstra
Copy link
Member

The failure goes away with this diff, which disables the type cache:

diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 1cc6ca79298..4e4b3f79121 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -5437,7 +5437,7 @@ _PyType_LookupRef(PyTypeObject *type, PyObject *name)
     }
 #else
     if (entry->version == type->tp_version_tag &&
-        entry->name == name) {
+        entry->name == name && 0) {
         assert(type->tp_version_tag);
         OBJECT_STAT_INC_COND(type_cache_hits, !is_dunder_name(name));
         OBJECT_STAT_INC_COND(type_cache_dunder_hits, is_dunder_name(name));

So this is related to the type cache.

@Eclips4
Copy link
Member Author

Eclips4 commented Jun 20, 2024

Bisected to 3e8b609
cc @erlend-aasland

kumaraditya303 pushed a commit that referenced this issue Jul 3, 2024
…H-120829) (#120855)

* [3.13] gh-120782: Update internal type cache when reloading datetime

When reloading _datetime module, the single-phase version did not invoke the PyInit__datetime function, whereas the current multi-phase version updates the static types through the module init. The outdated static type cache in the interpreter state needs to be invalidated at the end of reloading the multi-phase module.
@neonene
Copy link
Contributor

neonene commented Aug 7, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants