Possible bug in EnumCol/EnumValidator

Gert Burger <[email protected]> Wed, 07 Aug 2013 11:52:15 +0200
Newsgroups gmane.comp.python.sqlobject
Message-ID <[email protected]>
Hi

Attached is a test case demonstrating the issue. Tested with version
1.5.0b1 and some previous versions.

The EnumValidator checks if the value given is in the list of valid
enumValues but this allows unicode values to match normal string values.

That allows unicode objects into the SQL generation code which forces
python to create unicode strings instead of normal strings. This means
already encoded values will be decoded again and probably with the wrong
encoding.

My guess is that the EnumValidator should return only str objects that
are properly encoded.

Regards
Gert Burger

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk

_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
test_so_bug.py (text/x-python, 616 B)
import logging
logging.basicConfig(level=logging.DEBUG)

from sqlobject import SQLObject, connectionForURI, UnicodeCol, EnumCol

class TestObject(SQLObject):
    class sqlmeta:
        cacheValues = False
    name = UnicodeCol()
    enum = EnumCol(enumValues=['val1', 'val2'], default='val1')

conn = connectionForURI('sqlite:/:memory:')
print conn.getConnection()
conn.debug = 1
TestObject._connection = conn
TestObject.createTable()

TestObject(name=u'test', enum='val1')
TestObject(name=u'test', enum=u'val1')
TestObject(name=u'\u201c', enum='val1')

TestObject(name=u'\u201c', enum=u'val1') #Only this one fails