mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-03 05:34:01 +00:00
Fixed a bug in reporting Python code validation (#11522)
- **Description:** fixed a bug in pal-chain when it reports Python code validation errors. When node.func does not have any ids, the original code tried to print node.func.id in raising ValueError. - **Issue:** n/a, - **Dependencies:** no dependencies, - **Tag maintainer:** @hazzel-cn, @eyurtsev - **Twitter handle:** @lazyswamp --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
9f39c23a13
commit
fbb82608cd
@ -226,24 +226,26 @@ class PALChain(Chain):
|
|||||||
or not code_validations.allow_imports
|
or not code_validations.allow_imports
|
||||||
):
|
):
|
||||||
for node in ast.walk(code_tree):
|
for node in ast.walk(code_tree):
|
||||||
if (
|
if (not code_validations.allow_command_exec) and isinstance(
|
||||||
(not code_validations.allow_command_exec)
|
node, ast.Call
|
||||||
and isinstance(node, ast.Call)
|
|
||||||
and (
|
|
||||||
(
|
|
||||||
hasattr(node.func, "id")
|
|
||||||
and node.func.id in COMMAND_EXECUTION_FUNCTIONS
|
|
||||||
)
|
|
||||||
or (
|
|
||||||
isinstance(node.func, ast.Attribute)
|
|
||||||
and node.func.attr in COMMAND_EXECUTION_FUNCTIONS
|
|
||||||
)
|
|
||||||
)
|
|
||||||
):
|
):
|
||||||
raise ValueError(
|
if (
|
||||||
f"Found illegal command execution function "
|
hasattr(node.func, "id")
|
||||||
f"{node.func.id} in code {code}"
|
and node.func.id in COMMAND_EXECUTION_FUNCTIONS
|
||||||
)
|
):
|
||||||
|
raise ValueError(
|
||||||
|
f"Found illegal command execution function "
|
||||||
|
f"{node.func.id} in code {code}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
isinstance(node.func, ast.Attribute)
|
||||||
|
and node.func.attr in COMMAND_EXECUTION_FUNCTIONS
|
||||||
|
):
|
||||||
|
raise ValueError(
|
||||||
|
f"Found illegal command execution function "
|
||||||
|
f"{node.func.attr} in code {code}"
|
||||||
|
)
|
||||||
|
|
||||||
if (not code_validations.allow_imports) and (
|
if (not code_validations.allow_imports) and (
|
||||||
isinstance(node, ast.Import) or isinstance(node, ast.ImportFrom)
|
isinstance(node, ast.Import) or isinstance(node, ast.ImportFrom)
|
||||||
|
Loading…
Reference in New Issue
Block a user