On Mon, Oct 11, 2010 at 06:17:02PM +0200, Georges Schutz wrote:
> import sqlobject as sobj
>
> class Person(sobj.SQLObject):
> name = sobj.StringCol(default=None)
>
> conn = sobj.connectionForURI('sqlite:/:memory:')
>
> Person.createTable(ifNotExists=True, connection=conn)
> Person(name="P. Dummy", connection=conn)
>
> p = Person.selectBy(name = "P. Dummy", connection=conn)
...
> File
> "C:\Python26\lib\site-packages\sqlobject-0.14.0-py2.6.egg\sqlobject\dbconnection.py",
> line 850, in getConnection
> "No connection has been defined for this thread "
> AttributeError: No connection has been defined for this thread or process
Congratulations, you managed to find quite a subtle problem! Sometimes
validators need additional information from connection - most often
validators need encoding (charset) to convert between str and unicode. In
your example there is no per-class connection, and validators don't get a
connection at all. In many cases it could be fixed - the attached patch is
for testing and discussing.
The problem is rather old but it manifested itself now because in
version 0.13 I refactored validators' code.
> conn = sobj.connectionForURI('sqlite:/:memory:')
> ^^^^^^^^
> Person.createTable(ifNotExists=True, connection=conn)
^^^^^^^^^^^^^^^^
I seems you prepared memory to be rather persistent! (Just kidding.)
Oleg.
--
Oleg Broytman http://phd.pp.ru/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|