I have a patch for a bug I found in the DecimalValidator class in col.py.  I
am getting messages saying no attribute 'name' of DecimalValidator.  This is
is traceable to col.py, about line 1300:



def from_python(self, value, state):

    if value is None:

        return None

    if isinstance(value, float):

        value = str(value)

    if isinstance(value, (str, unicode)):

        connection = state.soObject._connection

        if hasattr(connection, "decimalSeparator"):

            value = value.replace(connection.decimalSeparator, ".")

        try:

            return Decimal(value)

        except:

            raise validators.Invalid("can not parse Decimal value '%s' in
the DecimalCol from '%s'" %

                (value, getattr(state, 'soObject', '(unknown)')), value,
state)

    if not isinstance(value, (int, long, Decimal,
sqlbuilder.SQLExpression)):

        raise validators.Invalid("expected a decimal in the DecimalCol '%s',
got %s %r instead" % \

            (getattr(self, 'name', '(unknown name)'), type(value), value),
value, state)

    return value





The change is in the next-to-last line (the raise() call).  The problem, as
I mentioned, is DecimalValidator having no attribute 'name' (a reference to
self.name).  Changing self.name to getattr(self, 'name', '(unknown
name)')eliminates this problem and preserves a nice error message
showing you what
the problem is.



Likewise, there’s a line above this in the to_python() method that
could/should be changed similarly.



Sorry, I don’t know how to create a test for this, my code is rather
complex.



-- Kevin
------------------------------------------------------------------------------
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to