René's URL Explorer Experiment


Title: `TimedRotatingFileHandler` misnames backups around DST changes · Issue #160433 · python/cpython · GitHub

Open Graph Title: `TimedRotatingFileHandler` misnames backups around DST changes · Issue #160433 · python/cpython

X Title: `TimedRotatingFileHandler` misnames backups around DST changes · Issue #160433 · python/cpython

Description: Bug report Summary With local time (utc=False), TimedRotatingFileHandler can give a backup the wrong date or hour when a daylight saving time (DST) change is involved. For fixed-duration rollovers such as when='H' and when='D', the affec...

Open Graph Description: Bug report Summary With local time (utc=False), TimedRotatingFileHandler can give a backup the wrong date or hour when a daylight saving time (DST) change is involved. For fixed-duration rollovers ...

X Description: Bug report Summary With local time (utc=False), TimedRotatingFileHandler can give a backup the wrong date or hour when a daylight saving time (DST) change is involved. For fixed-duration rollovers ...

Opengraph URL: https://github.com/python/cpython/issues/160433

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`TimedRotatingFileHandler` misnames backups around DST changes","articleBody":"### Bug report\n\n### Summary\n\nWith local time (`utc=False`), `TimedRotatingFileHandler` can give a backup the wrong date or hour when a daylight saving time (DST) change is involved. For fixed-duration rollovers such as `when='H'` and `when='D'`, the affected interval spans the change. For `when='midnight'`, a record logged well after the scheduled rollover can also cause the wrong name. If the computed name already exists, the handler skips that rotation, advances the next rollover time, and later resumes rotating. Records from separate intervals can then end up in the same backup.\n\n### Reproduction Code\n\nUnix only (`time.tzset()` and the `America/New_York` timezone are required). \n\nHourly rollover across the start of DST:\n\n```python\nimport logging, logging.handlers, os, tempfile, time\nfrom unittest import mock\n\nos.environ[\"TZ\"] = \"America/New_York\"\ntime.tzset()\n\nd = tempfile.mkdtemp()\nfn = os.path.join(d, \"app.log\")\nstart = time.mktime((2026, 3, 7, 23, 0, 0, 0, 0, -1))\nnow = [start]\nwith mock.patch(\"time.time\", lambda: now[0]):\n    h = logging.handlers.TimedRotatingFileHandler(fn, when=\"H\", delay=True)\n    for i in range(6):\n        now[0] = start + i * 3600\n        msg = time.strftime(\"%H:%M%Z\", time.localtime(now[0]))\n        h.emit(logging.makeLogRecord({\"msg\": msg}))\nh.close()\nfor name in sorted(os.listdir(d)):\n    with open(os.path.join(d, name)) as f:\n        print(name, f.read().split())\n```\n\nMidnight rollover when the first record on the day DST ends arrives after the change:\n\n```python\nimport logging, logging.handlers, os, tempfile, time\nfrom unittest import mock\n\nos.environ[\"TZ\"] = \"America/New_York\"\ntime.tzset()\n\nd = tempfile.mkdtemp()\nfn = os.path.join(d, \"app.log\")\nts = lambda *args: time.mktime(args + (0, 0, -1))\nnow = [ts(2026, 10, 30, 8, 0, 0)]\nwith mock.patch(\"time.time\", lambda: now[0]):\n    h = logging.handlers.TimedRotatingFileHandler(fn, when=\"midnight\", delay=True)\n    for day in [(2026, 10, 30), (2026, 10, 31), (2026, 11, 1),\n                (2026, 11, 2), (2026, 11, 3)]:\n        for hour in (9, 18):\n            now[0] = ts(*day, hour, 0, 0)\n            msg = time.strftime(\"%m-%d_%H:%M%Z\", time.localtime(now[0]))\n            h.emit(logging.makeLogRecord({\"msg\": msg}))\nh.close()\nfor name in sorted(os.listdir(d)):\n    with open(os.path.join(d, name)) as f:\n        print(name, f.read().split())\n```\n\nSparse records with a 23:30 daily rollover:\n\n```python\nimport datetime, logging, logging.handlers, os, tempfile, time\nfrom unittest import mock\n\nos.environ[\"TZ\"] = \"America/New_York\"\ntime.tzset()\n\nd = tempfile.mkdtemp()\nfn = os.path.join(d, \"app.log\")\nts = lambda *args: time.mktime(args + (0, 0, -1))\nnow = [ts(2026, 3, 1, 12, 0, 0)]\nwith mock.patch(\"time.time\", lambda: now[0]):\n    h = logging.handlers.TimedRotatingFileHandler(\n        fn, when=\"midnight\", atTime=datetime.time(23, 30), delay=True)\n    for args in [(2026, 3, 1, 12, 0, 0), (2026, 4, 1, 12, 0, 0),\n                 (2026, 10, 1, 12, 0, 0), (2026, 12, 1, 12, 0, 0)]:\n        now[0] = ts(*args)\n        msg = time.strftime(\"%m-%d_%H:%M%Z\", time.localtime(now[0]))\n        h.emit(logging.makeLogRecord({\"msg\": msg}))\nh.close()\nfor name in sorted(os.listdir(d)):\n    with open(os.path.join(d, name)) as f:\n        print(name, f.read().split())\n```\n\n### Actual Behavior\n\nHourly rollover saves the `01:00EST` interval as `_03`. The next interval also maps to `_03`, so that rotation is skipped. Rotation resumes later, with `03:00EDT` and `04:00EDT` together in `_04`:\n\n```text\napp.log ['05:00EDT']\napp.log.2026-03-07_23 ['23:00EST']\napp.log.2026-03-08_00 ['00:00EST']\napp.log.2026-03-08_03 ['01:00EST']\napp.log.2026-03-08_04 ['03:00EDT', '04:00EDT']\n```\n\nMidnight rollover skips the rotation on November 1 because it computes the already used October 30 name for the October 31 interval. The next rotation puts October 31 and November 1 in `_11-01`:\n\n```text\napp.log ['11-03_09:00EST', '11-03_18:00EST']\napp.log.2026-10-30 ['10-30_09:00EDT', '10-30_18:00EDT']\napp.log.2026-11-01 ['10-31_09:00EDT', '10-31_18:00EDT', '11-01_09:00EST', '11-01_18:00EST']\napp.log.2026-11-02 ['11-02_09:00EST', '11-02_18:00EST']\n```\n\nWith sparse records and `atTime`, the March 1 record is saved under March 1 rather than February 28:\n\n```text\napp.log ['12-01_12:00EST']\napp.log.2026-03-01 ['03-01_12:00EST']\napp.log.2026-03-31 ['04-01_12:00EDT']\napp.log.2026-09-30 ['10-01_12:00EDT']\n```\n\n### Expected Behavior\n\nThe `doRollover()` docstring says a backup is named for the start of its interval. In the hourly example, the `01:00EST` record should be in `_01`, followed by separate `_03` and `_04` backups. In the midnight example, each day from October 30 through November 2 should have its own backup. In the sparse `atTime` example, the first backup should be dated February 28.\n\n### Root Cause\n\n`doRollover()` starts with `t = self.rolloverAt - self.interval`, then compares the DST state of `t` with that of the record that triggered rotation. When they differ, it shifts the time used for the filename by one hour. This adjustment runs for every `when` value. For fixed-duration rollovers, `t` is already the interval start, so the shift can misname it. For midnight and weekly rollovers, the triggering record can arrive long after `rolloverAt`; its DST state need not match the DST state at the scheduled boundary.\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-160564\n* gh-160577\n* gh-160578\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/lpyu001","@type":"Person","name":"lpyu001"},"datePublished":"2026-10-23T14:24:41Z","url":"https://github.com/python/cpython/issues/160433"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e9050f6e-5769-7ac9-2d64-c5f3d325d9ad
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBD72:33943:106999C:15C62BA:6B064FF8
html-safe-nonce12e8d4300fe81c385102092468a55ac7dc16096ef6d1976148f38ef53cd80691
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDcyOjMzOTQzOjEwNjk5OUM6MTVDNjJCQTo2QjA2NEZGOCIsInZpc2l0b3JfaWQiOiI2ODQzMTQ5MzY5OTIwMDgxOTEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac63bbdb9f44e13eaae7c3345bbc7c951bfeb4588132530bf16250c951ced54c07
hovercard-subject-tagissue:5999583730
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/160433/issue_layout
twitter:imagehttps://opengraph.githubassets.com/18cc1da09c23ece9558c05ff418cd3d3523ae76ff83dc91c4469a61bb0ec4de4/python/cpython/issues/160433
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/18cc1da09c23ece9558c05ff418cd3d3523ae76ff83dc91c4469a61bb0ec4de4/python/cpython/issues/160433
og:image:altBug report Summary With local time (utc=False), TimedRotatingFileHandler can give a backup the wrong date or hour when a daylight saving time (DST) change is involved. For fixed-duration rollovers ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelpyu001
hostnamegithub.com
expected-hostnamegithub.com
None772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef1f9a08f7c769a37f1dfc18ad43d463c222a7eea
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/160433#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F160433
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F160433
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/160433
Reloadhttps://github.com/python/cpython/issues/160433
Reloadhttps://github.com/python/cpython/issues/160433
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/160433
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/160433
#160564https://github.com/python/cpython/pull/160564
TimedRotatingFileHandler misnames backups around DST changeshttps://github.com/python/cpython/issues/160433#top
#160564https://github.com/python/cpython/pull/160564
stdlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-bughttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/lpyu001
lpyu001https://github.com/lpyu001
on Oct 23, 2026https://github.com/python/cpython/issues/160433#issue-5999583730
gh-160433: Correct timed log backup names across DST changes #160564https://github.com/python/cpython/pull/160564
[3.14] gh-160433: Correct timed log backup names across DST changes (GH-160564) #160577https://github.com/python/cpython/pull/160577
[3.15] gh-160433: Correct timed log backup names across DST changes (GH-160564) #160578https://github.com/python/cpython/pull/160578
lpyu001https://github.com/lpyu001
type-bughttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Oct 23, 2026https://github.com/python/cpython/issues/160433#event-34060061342
https://github.com/lpyu001
lpyu001https://github.com/lpyu001
on Oct 23, 2026https://github.com/python/cpython/issues/160433#issuecomment-6368864403
aiskhttps://github.com/aisk
stdlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Oct 23, 2026https://github.com/python/cpython/issues/160433#event-34069797179
aiskhttps://github.com/aisk
Logging issues 🪵https://github.com/orgs/python/projects/15
on Oct 23, 2026https://github.com/python/cpython/issues/160433#event-34069810337
https://github.com/lpyu001
lpyu001https://github.com/lpyu001
on Oct 23, 2026https://github.com/python/cpython/issues/160433#issuecomment-6376387980
vsajiphttps://github.com/vsajip
on Oct 24, 2026https://github.com/python/cpython/issues/160433#event-34115745412
gh-160433: Correct timed log backup names across DST changes (GH-160564)https://github.com/python/cpython/commit/457ba33e96e644b402ea83bd6079af264b192ffb
gh-160433https://github.com/python/cpython/issues/160433
GH-160564https://github.com/python/cpython/pull/160564
457ba33https://github.com/python/cpython/commit/457ba33e96e644b402ea83bd6079af264b192ffb
vsajiphttps://github.com/vsajip
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#160564https://github.com/python/cpython/pull/160564
on Oct 24, 2026https://github.com/python/cpython/issues/160433#event-34115745624
github-project-automationhttps://github.com/apps/github-project-automation
Logging issues 🪵https://github.com/orgs/python/projects/15
on Oct 24, 2026https://github.com/python/cpython/issues/160433
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/160433
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/160433
stdlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-bughttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Logging issues 🪵https://github.com/orgs/python/projects/15
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.