Hi John,
Thanks for your reply, I was feeling pretty desperate already with no one
talking to me :(

On Mon, 11 Apr 2005 11:46:20 +1000, John Machin wrote:
> Are you sure that is the code that you are executing? What is "x"? What is
> "self.d"? "each" is not used. Even if "x" and "self.d" do exist, the for
> loop will do nothing, and the method will return an empty dictionary.

You are right, I'm sorry, my code has comments and variable names in
Spanish, so i made a translation of it. Obviously i was more stressed out
than i can remember and i came up with that nasty mess. The actual code is:


    def get_vars(self):
        if self.d == {}:
            for x in self.fs.list:
                self.d[x.name] = x.value
        return self.d

> Assuming self.d does exist, why does it exist? I.e for what reason do you
> want the data to persist? Could its persistence be the cause of your
> problem? Are you sure you are not accidentally always referring to the
> same VarsWrapper instance?

self.d is initialized as "{}" on __init__(), and i'm using self.d this way
so that the parsing is done only once, upon get_vars() first call. After
this, self.d will be different than {} and i will just get the values.

Referring to the same VarsWrapper instance (or the same instance of some
other object) sounds like a plausible cause for my problem, since it works
the first time (upon the first instantiation) and keeps the same values
later. The problem is, I really don't see any way this could be happening.
I've checked the corresponding parts of the code a few hundred times rigth
now and I've made sure that every object is new and not reused. This is,
of course, unless there's some unexpected behaviour in mod_python (thing
like variables staying "alive" between executions of a script, or
something like this).

> Is that all that VarsWrapper contains? Seems to me like an unnecessary and
> possibly confusing convolution. If you "own" util.FieldStorage, then
> giving it an as_dictionary() method might be a good idea. Otherwise a
> simple wrapper *function* that replaces your two-step __init__ and
> get_vars would be a not unreasonable idea; there's no law that says that
> everything must be a class.

I guess you are right on this, actually the util.FieldStorage
implementation just replaced an older util.parse_qs() one that provided
with separated get_getvars() and get_postvars() methods, aside from the
get_vars() one. I went back to util.FieldStorage when I found this issue,
in order to reduce the possible origins for this behaviour.

> Are you sure you don't have a dict as a default arg somewhere, like
> in def handle(self, vars={})  ??

I'm positive about this: my code works fine right after a restart of the
server, but keeps seeing the same data after the first request, so the
bug is about unwanted persistence of the first request data, not about
defaults.

Anyway, I will try replacing VarsWrapper with a simple function in order
to avoid yet another possible bug cause.

Thanks again for your help, and if something else comes to your mind I
would really appreciate to hear about it, since i've pretty much ran out
of ideas by now. Anyhow, I will work on it some more tomorrow afternoon,
I'm taking a well deserved break now :D

Gonzalo
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to