Skip to content

Commit

Permalink
Merge pull request #491 from beer-garden/parameter-fix
Browse files Browse the repository at this point in the history
Fix parameter type when no type is specified
  • Loading branch information
TheBurchLog authored Jul 12, 2024
2 parents 0a76c85 + ba626b3 commit 4d1bcf9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Brewtils Changelog
------
TBD

- Fixed bug where parameter type mapping did not match type hinting
- Exposed a read only feature to provide the current request that is being processed `from brewtils import get_current_request_read_only`
- Expand Job Export to include Job id

Expand Down
27 changes: 14 additions & 13 deletions brewtils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,20 @@ def echo(self, message):
"""

# Validate type against permitted string literals
if not isinstance(type, str):
# Try to map literal to string equivalent
temp_type = _format_type(type)
if temp_type in Parameter.TYPES:
type = temp_type
elif type not in Parameter.TYPES:
# Allowing type matching: string == String == STRING
for parameter_type in Parameter.TYPES:
if type.upper() == parameter_type.upper():
type = parameter_type
break
if type not in Parameter.TYPES:
raise ValueError(f"Unable to map type {type} to string literal")
if type:
if not isinstance(type, str):
# Try to map literal to string equivalent
temp_type = _format_type(type)
if temp_type in Parameter.TYPES:
type = temp_type
elif type not in Parameter.TYPES:
# Allowing type matching: string == String == STRING
for parameter_type in Parameter.TYPES:
if type.upper() == parameter_type.upper():
type = parameter_type
break
if type not in Parameter.TYPES:
raise ValueError(f"Unable to map type {type} to string literal")

if _wrapped is None:
return functools.partial(
Expand Down
2 changes: 1 addition & 1 deletion test/decorators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def cmd6(foo):
assert cmd3.parameters[0].type == "Float"
assert cmd4.parameters[0].type == "Boolean"
assert cmd5.parameters[0].type == "Dictionary"
assert cmd6.parameters[0].type == "Any"
assert cmd6.parameters[0].type is None

with pytest.raises(ValueError):

Expand Down

0 comments on commit 4d1bcf9

Please sign in to comment.