# HG changeset patch # User Adrien Di Mascio # Date 1253869283 -7200 # Node ID c9c8b231db7bb8c87b32e52d493f92738f71c6db # Parent 0ad4ef5d373716eade5fca9adb011a3e0938c6af [forms] fix form_needs_multipart implementation problem ------- The current implementation of form_needs_multipart goes down recursively in all inlined forms to check if one of them needs a multipart enctype. If we have a relation definition as X part_of X, the previous implementation potentially lead to an infinite recursion diff -r 0ad4ef5d3737 -r c9c8b231db7b web/views/autoform.py --- a/web/views/autoform.py Wed Sep 23 18:23:52 2009 +0200 +++ b/web/views/autoform.py Fri Sep 25 11:01:23 2009 +0200 @@ -192,6 +192,11 @@ @property def form_needs_multipart(self): """true if the form needs enctype=multipart/form-data""" + return self._subform_needs_multipart() + + def _subform_needs_multipart(self, _tested=None): + if _tested is None: + _tested = set() if super(AutomaticEntityForm, self).form_needs_multipart: return True # take a look at inlined forms to check (recursively) if they @@ -210,10 +215,17 @@ if len(targettypes) != 1: continue targettype = targettypes[0] + if targettype in _tested: + continue + _tested.add(targettype) if self.should_inline_relation_form(rschema, targettype, role): entity = self.vreg['etypes'].etype_class(targettype)(self.req) subform = self.vreg['forms'].select('edition', self.req, entity=entity) - if subform.form_needs_multipart: + if hasattr(subform, '_subform_needs_multipart'): + needs_multipart = subform._subform_needs_multipart(_tested) + else: + needs_multipart = subform.form_needs_multipart + if needs_multipart: return True return False