Stop time bombing with RuntimeError's

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2024-01-23 18:44:04 +00:00 committed by Pedro Algarvio
parent 166560c4c9
commit bbff5cec15
2 changed files with 19 additions and 5 deletions

View file

@ -0,0 +1 @@
Salt no longer time bombs user installations on code using `salt.utils.versions.warn_until_date`

View file

@ -6,12 +6,11 @@
which works under python 3 because on python 3 you can no longer compare
strings against integers.
"""
import datetime
import inspect
import logging
import numbers
import os
import sys
import warnings
@ -171,7 +170,7 @@ def warn_until(
if _version_ >= version:
caller = inspect.getframeinfo(sys._getframe(stacklevel - 1))
raise RuntimeError(
deprecated_message = (
"The warning triggered on filename '{filename}', line number "
"{lineno}, is supposed to be shown until version "
"{until_version} is released. Current version is now "
@ -180,8 +179,15 @@ def warn_until(
lineno=caller.lineno,
until_version=version.formatted_version,
salt_version=_version_.formatted_version,
),
)
)
if os.environ.get("RAISE_DEPRECATIONS_RUNTIME_ERRORS", "0") == "1":
# We don't raise RuntimeError by default since that can break
# users systems. We do however want to raise them in a CI context.
raise RuntimeError(deprecated_message)
# Otherwise, print the deprecated message to STDERR
sys.stderr.write(f"\n{deprecated_message}\n")
sys.stderr.flush()
if _dont_call_warnings is False:
warnings.warn(
@ -239,7 +245,7 @@ def warn_until_date(
today = _current_date or datetime.datetime.utcnow().date()
if today >= date:
caller = inspect.getframeinfo(sys._getframe(stacklevel - 1))
raise RuntimeError(
deprecated_message = (
"{message} This warning(now exception) triggered on "
"filename '{filename}', line number {lineno}, is "
"supposed to be shown until {date}. Today is {today}. "
@ -251,6 +257,13 @@ def warn_until_date(
today=today.isoformat(),
),
)
if os.environ.get("RAISE_DEPRECATIONS_RUNTIME_ERRORS", "0") == "1":
# We don't raise RuntimeError by default since that can break
# users systems. We do however want to raise them in a CI context.
raise RuntimeError(deprecated_message)
# Otherwise, print the deprecated message to STDERR
sys.stderr.write(f"\n{deprecated_message}\n")
sys.stderr.flush()
if _dont_call_warnings is False:
warnings.warn(