[Sqlalchemy-commits] [2825] sqlalchemy/trunk: improved handling of exceptions upon __init__(): will
Brought to you by:
zzzeek
From: <co...@sq...> - 2007-06-30 16:57:29
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[2825] sqlalchemy/trunk: improved handling of exceptions upon __init__(): will preserve the stack</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>2825</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2007-06-30 12:57:20 -0400 (Sat, 30 Jun 2007)</dd> </dl> <h3>Log Message</h3> <pre>improved handling of exceptions upon __init__(): will preserve the stack trace of the original __init__ exception; errors raised during session.expunge() will be reported as warnings</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunklibsqlalchemyormmapperpy">sqlalchemy/trunk/lib/sqlalchemy/orm/mapper.py</a></li> <li><a href="#sqlalchemytrunklibsqlalchemyutilpy">sqlalchemy/trunk/lib/sqlalchemy/util.py</a></li> <li><a href="#sqlalchemytrunktestormmapperpy">sqlalchemy/trunk/test/orm/mapper.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunklibsqlalchemyormmapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/orm/mapper.py (2824 => 2825)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/orm/mapper.py 2007-06-30 16:36:42 UTC (rev 2824) +++ sqlalchemy/trunk/lib/sqlalchemy/orm/mapper.py 2007-06-30 16:57:20 UTC (rev 2825) </span><span class="lines">@@ -670,13 +670,14 @@ </span><span class="cx"> if oldinit is not None: </span><span class="cx"> try: </span><span class="cx"> oldinit(self, *args, **kwargs) </span><del>- except Exception, e: - try: </del><ins>+ except: + def go(): </ins><span class="cx"> if session is not None: </span><span class="cx"> session.expunge(self) </span><del>- except: - pass # raise original exception instead - raise e </del><ins>+ # convert expunge() exceptions to warnings + util.warn_exception(go) + raise + </ins><span class="cx"> # override oldinit, insuring that its not already a Mapper-decorated init method </span><span class="cx"> if oldinit is None or not hasattr(oldinit, '_sa_mapper_init'): </span><span class="cx"> init._sa_mapper_init = True </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemyutilpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/util.py (2824 => 2825)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/util.py 2007-06-30 16:36:42 UTC (rev 2824) +++ sqlalchemy/trunk/lib/sqlalchemy/util.py 2007-06-30 16:57:20 UTC (rev 2825) </span><span class="lines">@@ -11,6 +11,8 @@ </span><span class="cx"> import dummy_threading as threading </span><span class="cx"> </span><span class="cx"> import md5 </span><ins>+import sys +import warnings </ins><span class="cx"> </span><span class="cx"> import __builtin__ </span><span class="cx"> </span><span class="lines">@@ -127,6 +129,13 @@ </span><span class="cx"> else: </span><span class="cx"> return default </span><span class="cx"> </span><ins>+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])) + </ins><span class="cx"> class SimpleProperty(object): </span><span class="cx"> """A *default* property accessor.""" </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunktestormmapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/orm/mapper.py (2824 => 2825)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/orm/mapper.py 2007-06-30 16:36:42 UTC (rev 2824) +++ sqlalchemy/trunk/test/orm/mapper.py 2007-06-30 16:57:20 UTC (rev 2825) </span><span class="lines">@@ -178,19 +178,16 @@ </span><span class="cx"> except Exception, e: </span><span class="cx"> assert e is ex </span><span class="cx"> </span><del>- class Bar(object): - def __init__(self): - object_session(self).expunge(self) - raise ex - - mapper(Bar, orders) - </del><ins>+ def bad_expunge(foo): + raise Exception("this exception should be stated as a warning") + + sess.expunge = bad_expunge </ins><span class="cx"> try: </span><del>- Bar(_sa_session=sess) </del><ins>+ Foo(_sa_session=sess) </ins><span class="cx"> assert False </span><span class="cx"> except Exception, e: </span><span class="cx"> assert e is ex </span><del>- </del><ins>+ </ins><span class="cx"> def testrefresh_lazy(self): </span><span class="cx"> """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""" </span><span class="cx"> s = create_session() </span></span></pre> </div> </div> </body> </html> |