Linux XFS filesystem development
 help / color / mirror / Atom feed
* xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py
@ 2025-08-26 13:15 Christian Kujau
  2025-08-26 15:57 ` Darrick J. Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Kujau @ 2025-08-26 13:15 UTC (permalink / raw)
  To: linux-xfs; +Cc: Darrick J. Wong

Running xfs_scrub_all under Python 3.13.5 prints the following warning:

----------------------------------------------
$ /usr/sbin/xfs_scrub_all --auto-media-scan-stamp \
   /var/lib/xfsprogs/xfs_scrub_all_media.stamp \
   --auto-media-scan-interval 1d
/usr/sbin/xfs_scrub_all:489: DeprecationWarning: 
datetime.datetime.utcnow() is deprecated and scheduled for removal in a 
future version. Use timezone-aware objects to represent datetimes in UTC: 
datetime.datetime.now(datetime.UTC).
  dt = datetime.utcnow()
Automatically enabling file data scrub.
----------------------------------------------

Python documentation for context: 
https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

Fix this by using datetime.now() instead.

NB: Debian/13 ships Python 3.13.5 and has a xfs_scrub_all.timer active, 
I'd assume that many systems will have that warning now in their logs :-)

Signed-off-by: Christian Kujau <lists@nerdbynature.de>

diff --git a/scrub/xfs_scrub_all.py.in b/scrub/xfs_scrub_all.py.in
index 515cc144..a94b1b71 100644
--- a/scrub/xfs_scrub_all.py.in
+++ b/scrub/xfs_scrub_all.py.in
@@ -496,8 +496,7 @@ def scan_interval(string):
 def utcnow():
 	'''Create a representation of the time right now, in UTC.'''
 
-	dt = datetime.utcnow()
-	return dt.replace(tzinfo = timezone.utc)
+	return datetime.now(timezone.utc)
 
 def enable_automatic_media_scan(args):
 	'''Decide if we enable media scanning automatically.'''


-- 
BOFH excuse #360:

Your parity check is overdrawn and you're out of cache.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-26 16:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26 13:15 xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py Christian Kujau
2025-08-26 15:57 ` Darrick J. Wong
2025-08-26 16:06   ` xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py [v2] Christian Kujau
2025-08-26 16:10     ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox