Matt Goodall wrote:
> The problem is probably best demonstrated by (untested) example with a
> description of what happens inside SQLObject's caches:
>
> id = Obj.new(col1='a', col2='b')
> # added to cache with key == int(1)
>
> o = Obj(id)
> # found in cache with key == int(1)
>
> o = Obj(str(id)) # note the cast to a string
> # reads from database, adds to cache with key == str(1)
> # Eek, two objects now in cache!
Argh! This problem is very easy to run into. For example, if you pass an
object ID to another page as a field variable, then it is all too easy
to forget that you have to cast the value back to an integer before
using it.
Example:
From one servlet that has fiddled with obj1 = MyObject(3), redirect to
another page with a URL like http://my.url/Index?id=3
Then in the Index.py servlet:
id = self.request().field("id")
obj2 = MyObject(id)
Oops! obj1 and obj2 aren't the same objects anymore! It's just too easy
to do this!!
...Edmund.
|