From 6b29c3beddc31bceeb17d09385dc2d2d04f0a97d Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 2 Mar 2020 14:09:10 +0100 Subject: [PATCH 1/2] misc: prevent infinite recursion when walking lazy formdata (#39803) --- wcs/qommon/substitution.py | 7 ++++++- wcs/variables.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/wcs/qommon/substitution.py b/wcs/qommon/substitution.py index b340e9a5..3c3e89f3 100644 --- a/wcs/qommon/substitution.py +++ b/wcs/qommon/substitution.py @@ -176,9 +176,14 @@ class CompatibilityNamesDict(dict): else: return for sub_key in sub_keys: + new_depth = depth - 1 + if not isinstance(sub_key, str): + sub_key, recurse = sub_key + if not recurse: + new_depth = 0 new_base = '%s_%s' % (base, sub_key) flat_keys[new_base] = None - flatten(new_base, depth=depth - 1) + flatten(new_base, depth=new_depth) for key in self.keys(): flatten(key) diff --git a/wcs/variables.py b/wcs/variables.py index edcfd329..d67aa11f 100644 --- a/wcs/variables.py +++ b/wcs/variables.py @@ -210,7 +210,10 @@ class LazyFormData(LazyFormDef): for key in dir(self): if key[0] == '_' or key in blacklist: continue - yield key + if key == 'parent': + yield key, False # = recurse + else: + yield key @property def objects(self): -- 2.24.0