Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[21.09] Skip non JSON-encodable values in params_to_strings() #13826

Open
wants to merge 3 commits into
base: release_21.09
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/galaxy/tools/parameters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Classes encapsulating Galaxy tool parameters.
"""

import logging
from json import dumps

from boltons.iterutils import remap
Expand All @@ -19,6 +19,8 @@
)
from .grouping import Conditional, Repeat, Section, UploadDataset

log = logging.getLogger(__name__)

REPLACE_ON_TRUTHY = object()

# Some tools use the code tag and access the code base, expecting certain tool parameters to be available here.
Expand Down Expand Up @@ -205,14 +207,21 @@ def params_to_strings(params, param_values, app, nested=False, use_security=Fals
Convert a dictionary of parameter values to a dictionary of strings
suitable for persisting. The `value_to_basic` method of each parameter
is called to convert its value to basic types, the result of which
is then json encoded (this allowing complex nested parameters and
is then JSON encoded (this allowing complex nested parameters and
such).
If the value is not JSON-encodable, the key/value pair is skipped.
"""
rval = dict()
for key, value in param_values.items():
if key in params:
value = params[key].value_to_basic(value, app, use_security=use_security)
rval[key] = value if nested or value is None else str(dumps(value, sort_keys=True))
if not nested and value is not None:
try:
value = dumps(value, sort_keys=True)
except Exception as e:
log.warning(f"Error while serializing value {value} for key {key}: {e}")
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems risky, don't you want to raise here ?

rval[key] = value
return rval


Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/util/bool_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from pyparsing import (
alphanums,
CaselessKeyword,
Forward,
infixNotation,
Keyword,
opAssoc,
Expand Down Expand Up @@ -132,7 +131,7 @@ def __init__(self, evaluator: TokenEvaluator, token_format: Optional[str] = None
action.evaluator = evaluator
boolOperand = TRUE | FALSE | Word(token_format or DEFAULT_TOKEN_FORMAT)
boolOperand.setParseAction(action)
self.boolExpr: Forward = infixNotation(
self.boolExpr: ParserElement = infixNotation(
boolOperand,
[
(NOT_OP, 1, opAssoc.RIGHT, BoolNot),
Expand Down