diff options
author | Solomon Tan <solomonbstoner@yahoo.com.au> | 2021-05-09 23:19:25 +0800 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2021-05-15 22:02:16 +0200 |
commit | 4870dcf68941194d16618887effd95fa32f99ba6 (patch) | |
tree | 69df4f6e8567052303648a864aa61d0025a46b6d /grc/core/blocks/embedded_python.py | |
parent | 6dbead201670462cfade299da6c0982e55663678 (diff) |
grc: Make exception for epy in blacklist id
I refer to the mailing list thread on May 8 2021 regarding "Embedded
Python Block Tutorial Param ID Error".
The bug is caused by #4522 as names of embedded python blocks
such as `epy_block_0` are blacklisted because of "blocks" in the
argument `black_listed_ids`. It affects both embedded python blocks and
modules. This commit fixes the bug by granting exemption for these two
types of blocks from id validation.
This commit makes the regex more strictly follow the naming convention
of epy blocks and modules so that only these will be fast-tracked
through the id validation. The naming convention appears to be a "epy"
prefix, followed by "block" or "module", and a number suffix.
This regex also takes into account the user copying-and-pasting the epy
blocks resulting in id names like `epy_block_0_0` and `epy_block_0_0_0`.
Instead of checking for epy blocks or modules using the naming
convention in the id like commit ac383d1 does, this commit checks by
looking at the block's key. All epy blocks and modules are identified
with the key `epy_block` and `epy_module` respectively.
This commit fixes the bug by changing the import name such that it does
not coincide with the generated id for epy blocks and modules. This
means that there no longer needs to be an exception case in the
validation id function for epy blocks and modules.
This commit fixes the bug by giving epy blocks and modules a new
attribute that grants them exemption from blacklist id validation.
Unlike v1, v2 and v3, this does not depend on the naming convention of
the block ids or block keys, which could change in the future, making
the code less of a hassle to maintain.
Improved on v5 (commit b85da80) with the following changes.
1. Changed `exempt_from_id_validation` from an instance variable to a
class variable since all instances of epy blocks and modules are
affected by the bug mentioned in v5.
2. Changed `hasattr` to `getattr` to prevent the bug where a block is
exempted from id validation when `exempt_from_id_validation=False`.
Improved from v6 (commit e66ed85). This grants the exemption to
blocks/modules only after they are marked for blacklist. This change
makes sure that the id exemption is used only to prevent the
blacklisting bug. The blocks/modules will still go through other forms
of id validation such as the naming convention check.
Signed-off-by: Solomon Tan <solomonbstoner@yahoo.com.au>
Diffstat (limited to 'grc/core/blocks/embedded_python.py')
-rw-r--r-- | grc/core/blocks/embedded_python.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/grc/core/blocks/embedded_python.py b/grc/core/blocks/embedded_python.py index c5b3cf0d36..051ba70317 100644 --- a/grc/core/blocks/embedded_python.py +++ b/grc/core/blocks/embedded_python.py @@ -70,6 +70,7 @@ class EPyBlock(Block): key = 'epy_block' label = 'Python Block' + exempt_from_id_validation = True # Exempt epy block from blacklist id validation documentation = {'': DOC} parameters_data = build_params( @@ -201,6 +202,7 @@ class EPyBlock(Block): class EPyModule(Block): key = 'epy_module' label = 'Python Module' + exempt_from_id_validation = True # Exempt epy module from blacklist id validation documentation = {'': dedent(""" This block lets you embed a python module in your flowgraph. |