From dae6e47c1858a3273bed0e7405a33f156f95ae7b Mon Sep 17 00:00:00 2001
From: Volker Schroer <3470424+dl1ksv@users.noreply.github.com>
Date: Tue, 12 Oct 2021 11:18:51 +0200
Subject: grc: Dependent variables sometimes fail to evaluate

fixes #4788
fixes #5100
fixes #5108

Tested with the coresponding examples.

Now disabling or deleting the symbol_rate block in #4788 correctly
updates the depending blocks

Signed-off-by: Volker Schroer <3470424+dl1ksv@users.noreply.github.com>
---
 grc/core/FlowGraph.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'grc/core/FlowGraph.py')

diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py
index aa9b1e4c61..ad42371bb8 100644
--- a/grc/core/FlowGraph.py
+++ b/grc/core/FlowGraph.py
@@ -227,6 +227,10 @@ class FlowGraph(Element):
 
     def renew_namespace(self):
         namespace = {}
+        # Before renewing the namespace, clear it
+        # to get rid of entries of blocks that
+        # are no longer valid ( deleted, disabled, ...)
+        self.namespace.clear()
         # Load imports
         for expr in self.imports():
             try:
@@ -262,6 +266,9 @@ class FlowGraph(Element):
                 pass
         namespace.update(np)  # Merge param namespace
 
+        # We need the updated namespace to evaluate the variable blocks
+        # otherwise sometimes variable_block rewrite / eval fails
+        self.namespace.update(namespace)
         # Load variables
         for variable_block in self.get_variables():
             try:
@@ -275,9 +282,7 @@ class FlowGraph(Element):
                 log.exception('Failed to evaluate variable block {0}'.format(variable_block.name), exc_info=True)
                 pass
 
-        self.namespace.clear()
         self._eval_cache.clear()
-        self.namespace.update(namespace)
 
     def evaluate(self, expr, namespace=None, local_namespace=None):
         """
-- 
cgit v1.2.3