From 5f3965ff0a67c4cba38c72d0e9aa49960bb7bb8a Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Fri, 3 Nov 2023 16:55:24 +0530 Subject: [PATCH] 1) Replace utcnow() function with datetime.now(timezone.utc) as it is deprecated from Python v3.12. 2) Correct the URL to log an issue in pgAdmin in the ERD tool script. --- web/pgadmin/misc/bgprocess/process_executor.py | 6 ++---- web/pgadmin/misc/bgprocess/processes.py | 7 ++----- .../static/js/erd_tool/components/ERDTool.jsx | 2 +- web/pgadmin/utils/passexec.py | 16 +++++++++++----- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/web/pgadmin/misc/bgprocess/process_executor.py b/web/pgadmin/misc/bgprocess/process_executor.py index 0d1c03ffd..8a6692a40 100755 --- a/web/pgadmin/misc/bgprocess/process_executor.py +++ b/web/pgadmin/misc/bgprocess/process_executor.py @@ -33,7 +33,7 @@ OUTDIR - Output directory # To make print function compatible with python2 & python3 import sys import os -from datetime import datetime, timedelta, tzinfo +from datetime import datetime, timedelta, tzinfo, timezone from subprocess import Popen, PIPE from threading import Thread import signal @@ -133,9 +133,7 @@ class UTC(tzinfo): def get_current_time(format='%Y-%m-%d %H:%M:%S.%f %z'): - return datetime.utcnow().replace( - tzinfo=UTC() - ).strftime(format) + return datetime.now(timezone.utc).strftime(format) class ProcessLogger(Thread): diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py index 4847b7624..f7d9e3554 100644 --- a/web/pgadmin/misc/bgprocess/processes.py +++ b/web/pgadmin/misc/bgprocess/processes.py @@ -16,7 +16,7 @@ import os import sys import psutil from abc import ABCMeta, abstractmethod -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from pickle import dumps, loads from subprocess import Popen, PIPE import logging @@ -29,7 +29,6 @@ from pgadmin.utils.constants import KERBEROS from pgadmin.utils.locker import ConnectionLocker from pgadmin.utils.preferences import Preferences -import pytz from dateutil import parser from flask import current_app, session from flask_babel import gettext as _ @@ -50,9 +49,7 @@ def get_current_time(format='%Y-%m-%d %H:%M:%S.%f %z'): """ Generate the current time string in the given format. """ - return datetime.utcnow().replace( - tzinfo=pytz.utc - ).strftime(format) + return datetime.now(timezone.utc).strftime(format) class IProcessDesc(metaclass=ABCMeta): diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx b/web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx index 8096c847b..0f2eb7205 100644 --- a/web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx +++ b/web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx @@ -668,7 +668,7 @@ class ERDTool extends React.Component { onSQLClick(sqlWithDrop=false) { let scriptHeader = gettext('-- This script was generated by the ERD tool in pgAdmin 4.\n'); - scriptHeader += gettext('-- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.\n'); + scriptHeader += gettext('-- Please log an issue at https://github.com/pgadmin-org/pgadmin4/issues/new/choose if you find any bugs, including reproduction steps.\n'); let url = url_for('erd.sql', { trans_id: this.props.params.trans_id, diff --git a/web/pgadmin/utils/passexec.py b/web/pgadmin/utils/passexec.py index 85a324693..d00be88c1 100644 --- a/web/pgadmin/utils/passexec.py +++ b/web/pgadmin/utils/passexec.py @@ -1,8 +1,14 @@ - - +########################################################################## +# +# pgAdmin 4 - PostgreSQL Tools +# +# Copyright (C) 2013 - 2023, The pgAdmin Development Team +# This software is released under the PostgreSQL License +# +########################################################################## import logging import subprocess -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from threading import Lock from flask import current_app @@ -31,7 +37,7 @@ class PasswordExec: if not self.cmd: return None current_app.logger.info('Calling passexec') - now = datetime.utcnow() + now = datetime.now(timezone.utc) try: p = subprocess.run( self.cmd, @@ -55,7 +61,7 @@ class PasswordExec: if self.expiration_seconds is None: return False return self.last_result is not None and\ - datetime.utcnow() - self.last_result \ + datetime.now(timezone.utc) - self.last_result \ >= timedelta(seconds=self.expiration_seconds) def create_logger(self):