[mod_python] Dictionary persistance weirdness

Gonzalo Sainz-Trápaga gomo at datafull.com
Sat Apr 9 15:38:35 EDT 2005


Hi,
I'm building my first application with mod_python. I am using Ian
Bicking's SQLObject, validators and HTMLfill among other tools.
I built a custom handler that parses the url and loads an external
module, passing it a request object and eventually, an ID integer that
is extracted from the URI.

Example:
http://site.com/race.py/4/signup will trigger "import race;
race.signup(4,req)" and that function will provide a form in order for
people to sign themselves up for race 4.

Form handling and data parsing (for POST or GET data) is done in
separate modules that are imported when needed, so race.py actually
imports formgen.py and formgen.py imports VarsWrapper (from wrappers.py)
in order to parse data for his form and tell whether he needs to print
an error message, or the input is valid.

The process works fine up to races.py: it gets the POSTed data fine, but
then if I try to pass the variables received to the form handler, the
handler will only receive them correctly on the first call to it after a
server restart. For later calls, the form handler sticks to the values
received on his first request.

Code snippets:

-- race.py -------------------------
def signup(id,req):
    from formgen import FormInscripcion

    v = VarsWrapper(req)
    c = v.get_vars()

    f = FormInscripcion(id)
    
    tpl.locals.contenido = f.handle(c)
    return tpl.get_html()


-- formgen.py -------------------------

class FormInscripcion:
(...)
    def handle(self,vars):
        # check for sent data
        if ('id_regata',str(self.id_regata)) in vars.items():
            return self._post(vars) # triggers a data handler
        else: 
            return self._form() # shows the clean form
(...)


-- wrappers.py -------------------------
class VarsWrapper:
    def __init__(self,req):
        self.fs = util.FieldStorage(req)

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


So again, the problem arises when calling FormInscripcion.handle() for
the 2nd time or more: it will stick to the data received on the 1st
request passed to it. If i print the variable dictionary (c in race.py,
vars in formgen.py) after the form, c will change with new POST data, as
vars will stay constant after the 1st request.
The weird thing is that i'm passing data from pyhandler.py to race.py in
the same way that i'm passing it from race.py to formgen.py, and it
refuses to work correctly in the latter.
I have already tried pretty much every single possible cause for this
oddity with no consistent results, so i'm pretty confident that there's
something i'm missing that's not inherent to my app's logic, but to my
app's login combined with some mod_python specific complication.
In short: i'm going nuts!
Sorry for all the writing, but I really hope somebody can help me.
Thanks in advance,

-- 
Gonzalo Sainz-Trápaga (GomoX)
GnuPG Fingerprint: A0AF 3BBF EB93 7EFE 6628  C5A5 F073 9442 6DE4 A497
Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x6DE4A497
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20050409/d59b9ae4/attachment.bin


More information about the Mod_python mailing list