quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anders Blomdell <anders.blomd...@control.lth.se>
Subject Bizarre behaviour in util.FieldStorage
Date Mon, 01 Mar 2010 11:34:45 GMT

When a FieldStorage has two (or more) Filed instances with the same value but
different names, the behaviour of programs like this is (more or less) undefined:

  fs = util.FieldStorage(req)
  fs['id1'] = 'New value'
  del fs['id2']

The reason for the undefinedness, is this code in __delitem__ (and the similar
in __setitem__):

        table = self.list.table()
        values = table[key]
        for value in values:

What happens is that the self.list.remove(value) will remove the first field
with a matching value, regardless of that fields name. Here is an example from
real life:

    form['id1'] = 'x'
    form['id2'] = 'x'
    form['id3'] = 'x'
    # Form now contains {'id2': [Field('id2', 'x')],
    #                    'id3': [Field('id3', 'x')],
    #                    'id1': [Field('id1', 'x')]}
    form['id2'] = 'y'
    # Form now contains {'id2': [Field('id2', 'x'), Field('id2', 'y')],
    #                    'id3': [Field('id3', 'x')]}
    # which is not what I would have expected

In my simple example, one solution, is to add the following method to StringField:

    def __eq__(self, other):
        return self.value == other.value and self.name == other.name

but this does not properly handle mixing Field and StringField. Anybody has a
better solution?


Anders Blomdell

Anders Blomdell                  Email: anders.blomdell@control.lth.se
Department of Automatic Control
Lund University                  Phone:    +46 46 222 4625
P.O. Box 118                     Fax:      +46 46 138118
SE-221 00 Lund, Sweden

View raw message