Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christian Kujau <lists@nerdbynature.de>
Cc: linux-xfs@vger.kernel.org, Andrey Albershteyn <aalbersh@redhat.com>
Subject: Re: xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py
Date: Tue, 26 Aug 2025 08:57:47 -0700	[thread overview]
Message-ID: <20250826155747.GB19817@frogsfrogsfrogs> (raw)
In-Reply-To: <ce844705-550d-3eb2-0d08-d779f9ebc029@nerdbynature.de>

On Tue, Aug 26, 2025 at 03:15:42PM +0200, Christian Kujau wrote:
> 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>

Heh heh heh.  That old code was for compatibility with RHEL6(?) back
when I started writing online fsck.  That's indeed no longer needed
because even RHEL7 supports datetime.now, so thank you for the update!

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> 
> 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.
> 

  reply	other threads:[~2025-08-26 15:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250826155747.GB19817@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=aalbersh@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lists@nerdbynature.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox