Modified to apply on 1.1.8 release From 5de8405307ded14930b3381380e9f91e583172a9 Mon Sep 17 00:00:00 2001 From: parrotpock <51694161+parrotpock@users.noreply.github.com> Date: Mon, 15 Nov 2021 17:39:23 +0100 Subject: [PATCH] Fix pyparsing > 3.0 compatibility issue. (#2727) * Fix bool() issue in recursion termination check. The behaviour of ParsedResults seems to have changed in the way that the usage of pop() along with the bool() check on the object interact wrt checking if there are further elements in the parsed structure to consume. In version > 3.0 bool() checks whether either the internal _toklist or _tokdict members contain items left to consume and returns True if either do, whereas pop with no arguments will only consume from the underlying list. That means that we would get a True in the if condition in this code, whereas a subsequent call to pop() would throw an exception. Calling asList() forces the use of the list representation in the bool check here and so fixes this issue. * Fix pyparsing backwards compatibility issue. * Remove upper-bound on pin. * Add pyparsing3 test target for versions >= 3.0.6 * Remove try/except, use dictionary key index syntax Co-authored-by: Ubuntu --- webapp/graphite/render/evaluator.py | 2 +- webapp/graphite/render/grammar_unsafe.py | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/webapp/graphite/render/evaluator.py b/webapp/graphite/render/evaluator.py index 748626ed0c..12179dcc44 100644 --- a/webapp/graphite/render/evaluator.py +++ b/webapp/graphite/render/evaluator.py @@ -58,7 +58,7 @@ def evaluateTokens(requestContext, tokens, replacements=None, pipedArg=None): return evaluateTokens(requestContext, tokens.template, arglist) if tokens.expression: - if tokens.expression.pipedCalls: + if tokens.expression.pipedCalls.asList(): # when the expression has piped calls, we pop the right-most call and pass the remaining # expression into it via pipedArg, to get the same result as a nested call rightMost = tokens.expression.pipedCalls.pop() diff --git a/webapp/graphite/render/grammar_unsafe.py b/webapp/graphite/render/grammar_unsafe.py index f25b5eff8f..2481176b53 100644 --- a/webapp/graphite/render/grammar_unsafe.py +++ b/webapp/graphite/render/grammar_unsafe.py @@ -80,7 +80,7 @@ def setRaw(s, loc, toks): - toks[0].raw = s[toks[0].start:toks[0].end] + toks[0]['raw'] = s[toks[0].start:toks[0].end] call = Group(