diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-16 18:07:06 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-18 10:41:52 -0400 |
| commit | 2051fa2ce9e724e6e77e19067d27d2660e7cd74a (patch) | |
| tree | 5cbff495b520116f4b8bfa35683ef4c1bd681785 /lib/sqlalchemy/util | |
| parent | d1948bc69bd0d26fbff77d7525ef899a2a9a580d (diff) | |
| download | sqlalchemy-2051fa2ce9e724e6e77e19067d27d2660e7cd74a.tar.gz | |
Add new "exec_once_unless_exception" system; apply to dialect.initialize
Fixed an issue whereby if the dialect "initialize" process which occurs on
first connect would encounter an unexpected exception, the initialize
process would fail to complete and then no longer attempt on subsequent
connection attempts, leaving the dialect in an un-initialized, or partially
initialized state, within the scope of parameters that need to be
established based on inspection of a live connection. The "invoke once"
logic in the event system has been reworked to accommodate for this
occurrence using new, private API features that establish an "exec once"
hook that will continue to allow the initializer to fire off on subsequent
connections, until it completes without raising an exception. This does not
impact the behavior of the existing ``once=True`` flag within the event
system.
Fixes: #4807
Change-Id: Iec32999b61b6af4b38b6719e0c2651454619078c
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 12fc5c0e8..f3f3f9ea5 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -1487,7 +1487,7 @@ def warn_limited(msg, args): warnings.warn(msg, exc.SAWarning, stacklevel=2) -def only_once(fn): +def only_once(fn, retry_on_exception): """Decorate the given function to be a no-op after it is called exactly once.""" @@ -1499,7 +1499,12 @@ def only_once(fn): strong_fn = fn # noqa if once: once_fn = once.pop() - return once_fn(*arg, **kw) + try: + return once_fn(*arg, **kw) + except: + if retry_on_exception: + once.insert(0, once_fn) + raise return go |
