if oldinit is not None:
try:
oldinit(instance, *args, **kwargs)
- except Exception, e:
- try:
- self.extension.init_failed(self, self.class_, instance, args, kwargs)
- except:
- pass # raise original exception instead
- raise e
+ except:
+ # call init_failed but suppress exceptions into warnings so that original __init__
+ # exception is raised
+ util.warn_exception(self.extension.init_failed, self, self.class_, instance, args, kwargs)
+ raise
# override oldinit, ensuring that its not already a Mapper-decorated init method
if oldinit is None or not hasattr(oldinit, '_oldinit'):
import md5
import sys
+import warnings
import __builtin__
try:
return dict
else:
return default
+
+def warn_exception(func, *args, **kwargs):
+ """executes the given function, catches all exceptions and converts to a warning."""
+ try:
+ return func(*args, **kwargs)
+ 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, extension=SessionContextExt(SessionContext()))
+ clear_mappers()
+ mapper(Foo, users, extension=SessionContextExt(SessionContext()))
+ 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