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

Deal with ParameterUninitializedException for parameter service #1033

Merged
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
1 change: 1 addition & 0 deletions rclpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ if(BUILD_TESTING)
test/test_messages.py
test/test_node.py
test/test_parameter.py
test/test_parameter_client.py
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
test/test_publisher.py
test/test_qos.py
test/test_qos_event.py
Expand Down
4 changes: 2 additions & 2 deletions rclpy/rclpy/parameter_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from rcl_interfaces.msg import SetParametersResult
from rcl_interfaces.srv import DescribeParameters, GetParameters, GetParameterTypes
from rcl_interfaces.srv import ListParameters, SetParameters, SetParametersAtomically
from rclpy.exceptions import ParameterNotDeclaredException
from rclpy.exceptions import ParameterNotDeclaredException, ParameterUninitializedException
from rclpy.parameter import Parameter, PARAMETER_SEPARATOR_STRING
from rclpy.qos import qos_profile_parameters
from rclpy.validate_topic_name import TOPIC_SEPARATOR_STRING
Expand Down Expand Up @@ -80,7 +80,7 @@ def _get_parameters_callback(self, request, response):
for name in request.names:
try:
param = node.get_parameter(name)
except ParameterNotDeclaredException:
except (ParameterNotDeclaredException, ParameterUninitializedException):
response.values = node.get_parameters([])
return response
response.values.append(param.get_parameter_value())
Expand Down
21 changes: 21 additions & 0 deletions rclpy/test/test_parameter_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,24 @@ def test_load_parameter_file_atomically(self):
finally:
if os.path.exists(f.name):
os.unlink(f.name)

def test_get_uninitialized_parameter(self):
self.target_node.declare_parameter('uninitialized_parameter', Parameter.Type.STRING)

# The type in description should be STRING
future = self.client.describe_parameters(['uninitialized_parameter'])
self.executor.spin_until_future_complete(future)
results = future.result()
assert results is not None
assert len(results.descriptors) == 1
assert results.descriptors[0].type == ParameterType.PARAMETER_STRING
assert results.descriptors[0].name == 'uninitialized_parameter'

# The value should be empty
future = self.client.get_parameters(['uninitialized_parameter'])
self.executor.spin_until_future_complete(future)
results = future.result()
assert results is not None
assert results.values == []

self.target_node.undeclare_parameter('uninitialized_parameter')