dabo Commit
Revision 7109
Date: 2012-03-11 09:57:41 -0700 (Sun, 11 Mar 2012)
Author: Paul
Trac: http://trac.dabodev.com/changeset/7109
Changed:
U trunk/dabo/db/dCursorMixin.py
Log:
Refactored _correctFieldType() to use the same error message for all cases.
Previously, the trial to convert to decimal was happening without being
tried, resulting in an unhandled exception after my recent changes (the
exception was being eaten in the execute() machinery before).
Diff:
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2012-03-10 20:52:43 UTC (rev 7108)
+++ trunk/dabo/db/dCursorMixin.py 2012-03-11 16:57:41 UTC (rev 7109)
@@ -238,13 +238,21 @@
# No conversion needed.
return field_val
+ def tryToCorrect(func, *args, **kwargs):
+ try:
+ return func(*args, **kwargs)
+ except Exception, e:
+ tfv = type(field_val)
+ dabo.log.info(_("_correctFieldType() failed for
field: "
+ "'%(field_name)s'; value:
'%(field_val)s'; type: '%(tfv)s'") % locals())
+
if pythonType in (unicode,):
# Unicode conversion happens below.
pass
elif pythonType in (datetime.datetime,) and
isinstance(field_val, basestring):
- return dates.getDateTimeFromString(field_val)
+ return tryToCorrect(dates.getDateTimeFromString,
field_val)
elif pythonType in (datetime.date,) and isinstance(field_val,
basestring):
- return dates.getDateFromString(field_val)
+ return tryToCorrect(dates.getDateFromString,field_val)
elif pythonType in (Decimal,):
ds = self.DataStructure
_field_val = field_val
@@ -259,14 +267,10 @@
scale = s[5]
if scale is None:
scale = 2
- return Decimal(_field_val).quantize(Decimal("0.%s" %
(scale * "0",)))
+ dec = tryToCorrect(Decimal, _field_val)
+ return dec.quantize(Decimal("0.%s" % (scale * "0",)))
else:
- try:
- return pythonType(field_val)
- except Exception, e:
- tfv = type(field_val)
- dabo.log.info(_("_correctFieldType() failed for
field: '%(field_name)s'; value: '%(field_val)s'; type: '%(tfv)s'")
- % locals())
+ return tryToCorrect(pythonType, field_val)
# Do the unicode conversion last:
if isinstance(field_val, str) and self._convertStrToUnicode:
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]