From dbaf82d258cc12d92ef28de4677d147fdb7808fd Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 11 Jun 2020 14:31:57 -0400 Subject: Add version token to error URL the sqlalche.me redirector now supports the numerical version code in the URL, e.g. /13/, /14/, /20/, etc., so that we can redirect to the error codes for the appropriate version of SQLAlchemy in use without going through the catch-all "latest" link. If a particular version of the docs is no longer on the site, the redirect will revert to falling through the "latest" link (which ultimately lands on the current release version, /13/ at the time of this writing). Change-Id: I3bb463fd6fb6c8767c95a57f3699aba715a9a72d --- lib/sqlalchemy/__init__.py | 4 ++++ lib/sqlalchemy/exc.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 27e9fd1c0..d52393d0b 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -142,5 +142,9 @@ def __go(lcls): _sa_util.preloaded.import_prefix("sqlalchemy") + from . import exc + + exc._version_token = "".join(__version__.split(".")[0:2]) + __go(locals()) diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index 92322fb90..491dde7b2 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -15,6 +15,8 @@ raised as a result of DBAPI exceptions are all subclasses of from .util import compat +_version_token = None + class SQLAlchemyError(Exception): """Generic error class.""" @@ -33,7 +35,7 @@ class SQLAlchemyError(Exception): else: return ( "(Background on this error at: " - "http://sqlalche.me/e/%s)" % (self.code,) + "http://sqlalche.me/e/%s/%s)" % (_version_token, self.code,) ) def _message(self, as_unicode=compat.py3k): -- cgit v1.2.1