Cyril Elkaim wrote:
> Hello,
>
> We have found the following two problems:
>
> If someone modify a property and then read it back the 'toPython'
> validator's method is _not_ called. In our case we are using a
> 'UnicaodeValidator' to store Unicode strings in UTF8 into a Postgres
> database, code follows:
>
>
> class UnicodeValidator(sqlobject.include.validators.Validator):
>
> def toPython(self, value, state=None):
> if value is None:
> return None
>
> return unicode(value,"utf8")
>
> def fromPython(self, value, state=None):
> if value is None:
> return None
>
> return value.encode("utf8")
I think there's a shortcut, so if you assign an attribute it goes
through fromPython to the database, but we keep the original value in an
instance variable. So when you later access the attribute, it's not
toPython(fromPython(originalValue)), but just the original value. This
might be noticeable because validators normalize values. Is this what
you are encountering? Is it causing a problem?
> Reading an object from the database from the first time correctly calls
> the validator 'toPython' method , but not after a write. Is somebody
> else having this problem? It arises even when disabling the cache. The
> 'fromPython' method _seems_ to be called every time.
>
> My second concern is with the parsing of the 'query' part in
> connectionFromURI; the values are assigned to properties as String and
> are not evaluated, for Boolean values (like enableing and disabling the
> cache) it ask for problems as setting cache=False always make a True
> value. A simple solution is to use eval before assigning the property
> inside the code of the method, but it may raise security problems. Again
> is somebody else having this problem?
Yeah, the query part isn't fully thought out. It works for booleans,
though -- the empty string is a false value, any non-empty string is
true. Some safe evaluator might be nice at some point, that knows how
to parse integers and some booleans (true/false, yes/no, etc).
> If I do a patch what is the procedure to post it and make it reviewed?
I guess mail it to the list. Bugs should go to the bug tracker on
sf.net. There's also a place for patches there, though I'm fine for a
patch going to either location.
> All in all the library is quite impressive and I must thank the author
> for his work.
Thanks.
--
Ian Bicking / ia...@co... / http://blog.ianbicking.org
|