trace of the original __init__ exception; errors raised during session.expunge() will be
reported as warnings
if oldinit is not None:
try:
oldinit(self, *args, **kwargs)
- except Exception, e:
- try:
+ except:
+ def go():
if session is not None:
session.expunge(self)
- except:
- pass # raise original exception instead
- raise e
+ # convert expunge() exceptions to warnings
+ util.warn_exception(go)
+ raise
+
# override oldinit, insuring that its not already a Mapper-decorated init method
if oldinit is None or not hasattr(oldinit, '_sa_mapper_init'):
init._sa_mapper_init = True
import dummy_threading as threading
import md5
+import sys
+import warnings
import __builtin__
else:
return default
+def warn_exception(func):
+ """executes the given function, catches all exceptions and converts to a warning."""
+ try:
+ return func()
+ except:
+ warnings.warn(RuntimeWarning("%s('%s') ignored" % sys.exc_info()[0:2]))
+
class SimpleProperty(object):
"""A *default* property accessor."""
except Exception, e:
assert e is ex
- class Bar(object):
- def __init__(self):
- object_session(self).expunge(self)
- raise ex
-
- mapper(Bar, orders)
-
+ def bad_expunge(foo):
+ raise Exception("this exception should be stated as a warning")
+
+ sess.expunge = bad_expunge
try:
- Bar(_sa_session=sess)
+ Foo(_sa_session=sess)
assert False
except Exception, e:
assert e is ex
-
+
def testrefresh_lazy(self):
"""test that when a lazy loader is set as a trigger on an object's attribute (at the attribute level, not the class level), a refresh() operation doesnt fire the lazy loader or create any problems"""
s = create_session()