You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
expand_topic_or_service_name should use get_effective_namespace() #985
sub_node concept is not being correctly used in some packages that use the function expand_topic_or_service_name(). They use it with get_namespace() to create publishers, instead of get_effective_namespace(). Probably many people do not know the existence of this method or the concept of subnode. For example, Here. If this node is a sub_node (created with create_sub_node(), then the effect of the subnode does not take effect. For:
Here. If this node is a sub_node (created with create_sub_node(), then the effect of the subnode does not take effect.
Yeah, that looks like it is just doing the wrong thing in that case.
Unfortunately, I see the problem that these things (like image transport) take the NodeBaseInterface and NodeTopicsInterface rather than a rclcpp::Node, and that's a problem because the subnode mechanism exists completely within a rclcpp::Node. We need some way to capture this and provide it to interfaces like this when needed... I do not, for example, think the right solution is to make the image transport only take a rclcpp::Node object.
The current implementation makes the sub-node namespace a property of the rclcpp::Node wrapper, not of the interfaces passed to consumers. The sub-node copy constructor shares node_base_, node_topics_, and the other interface objects with its parent, and computes sub_namespace_/effective_namespace_ only on the Node instance (rclcpp/src/rclcpp/node.cpp:259-275). Node itself prefixes relative names before delegating (rclcpp/include/rclcpp/node_impl.hpp:55-99), while NodeTopics::create_publisher passes the raw name and shared base to the factory (rclcpp/src/rclcpp/node_interfaces/node_topics.cpp:43-50). Consequently, a consumer holding only NodeBaseInterface or NodeTopicsInterface has no way to recover the effective namespace.
This is the interface-layer problem described in wjwwood's comment, not merely a bad expand_topic_or_service_name call in image_transport. Changing that utility to take rclcpp::Node would fix one consumer and make the layering worse. It would still leave lifecycle nodes, custom node-likes, and the existing interface-based APIs inconsistent.
Node should implement this with the same sub-namespace prefixing and remapping rules it already uses for create_publisher, create_subscription, and create_service. The context should be per sub-node; the physical NodeBaseInterface should continue to represent the one underlying rcl_node_t and should not change the meaning of get_namespace(). Conflating the physical and effective namespaces would break graph identity, fully-qualified node names, and code that intentionally asks for the physical namespace.
The context should be captured by the interface aggregate, not by requiring every consumer to know that a sub-node exists. NodeInterfaces currently just takes a tuple of interface shared_ptrs (rclcpp/include/rclcpp/node_interfaces/node_interfaces.hpp:43-65, and initialization at detail/node_interfaces_helpers.hpp:135-150). Add a NodeNameContextInterface::SharedPtr member to NodeInterfaces, populated from the originating node-like when available. The existing explicit constructor from loose interface pointers cannot infer the sub-namespace; it should accept an explicit context argument or use a documented root-context fallback.
For compatibility with consumers that still take individual interfaces:
Keep the existing raw NodeBaseInterface/NodeTopicsInterface overloads, but document them as root-context APIs when no context is supplied.
Add context-aware overloads for create_publisher, create_subscription, generic publishers/subscriptions, services/clients, and the action create functions. Prefer a single NodeInterfaces<...> or NodeNameContextInterface parameter over adding another unrelated raw pointer.
Have Node::get_node_*_interface() for a sub-node return a small sub-node-aware view or carry the context separately. A NodeTopics decorator can prefix/resolve names before forwarding to the shared root interface without changing the root interface's identity. A decorator is preferable to adding another virtual to NodeBaseInterface, which would be an ABI break and still cannot distinguish two sub-node wrappers that share one NodeBase.
Add NodeNameContextInterface to the aggregate requirements in image_transport's rolling RequiredInterfaces, rather than reverting image_transport to rclcpp::Node.
This gives three compatibility levels:
Node-like users automatically get sub-node behavior through NodeInterfaces.
Existing interface-only users continue to compile, with documented root behavior unless they pass a context.
Rolling-only APIs can migrate to the context-aware overloads and eventually deprecate the ambiguous interface-only overloads.
Affected call sites
The main paths to update are:
rclcpp/include/rclcpp/create_publisher.hpp:55-71: resolve QoS parameter names and create the publisher through the context.
rclcpp/include/rclcpp/create_subscription.hpp:64-81: the same path for subscriptions and QoS overrides.
rclcpp/src/rclcpp/node_interfaces/node_topics.cpp:43-50 and 73-90: create-view naming; resolve_topic_name at 141-145.
rclcpp/src/rclcpp/node_interfaces/node_services.cpp:78-82: service resolution.
rclcpp/src/rclcpp/node_interfaces/node_graph.cpp:456-460, 478-482, 500-504, 522-526, 670-674, and 785-789: graph queries currently expand from the physical RCL namespace.
rclcpp_action/src/graph.cpp:77-81 and 122-126, plus the raw-interface overloads in rclcpp_action/include/rclcpp_action/create_server.hpp:58-68 and the corresponding client functions.
rclcpp/include/rclcpp/node_impl.hpp:73, 94, 145, 161, 179, 196, and 214: keep these as the Node convenience methods, but delegate to the same context rather than duplicating prefix rules.
rclcpp/src/rclcpp/parameter_event_handler.cpp:238 and similar direct uses of NodeBaseInterface::get_namespace() should be audited; not every use should switch to the effective namespace.
Lower-level publisher/subscription/client/service constructors also call expand_topic_or_service_name for validation using the RCL node handle's physical namespace (publisher_base.cpp:86-89, subscription_base.cpp:89-92). Those paths are usually reached after the higher layer has resolved the name; they should either accept the context for correct diagnostics or remain explicitly root-oriented rather than guessing.
Minimal migration path
Add NodeNameContextInterface and implement it on rclcpp::Node; make LifecycleNode provide the root/effective context it can currently represent.
Teach NodeInterfaces to capture the context from a node-like, and add a two-argument constructor for explicit loose-interface aggregation.
Update core create_* and graph/action helpers to use the context when it is present.
Update image_transport's aggregate to require the context and add an end-to-end sub-node test for advertiseCamera.
Keep the old overloads for one compatibility cycle, then deprecate only the ones whose behavior cannot be made correct from their arguments.
Regression tests should cover relative names under nested sub-nodes, absolute names, ~ private substitutions, remaps applied after the sub-namespace prefix, a consumer receiving NodeInterfaces from a sub-node, and a consumer using the explicit root-only overload. The important negative test is that a loose NodeBaseInterface cannot magically infer a calling sub-node's namespace; the API should require an explicit context instead of silently doing the wrong thing.
Activity
wjwwood commentedon Feb 24, 2020
Yeah, that looks like it is just doing the wrong thing in that case.
Unfortunately, I see the problem that these things (like image transport) take the
NodeBaseInterfaceandNodeTopicsInterfacerather than arclcpp::Node, and that's a problem because the subnode mechanism exists completely within arclcpp::Node. We need some way to capture this and provide it to interfaces like this when needed... I do not, for example, think the right solution is to make the image transport only take arclcpp::Nodeobject.0.15.0 (ros2#985)
Quchaosheng commentedon Oct 21, 2026
The current implementation makes the sub-node namespace a property of the
rclcpp::Nodewrapper, not of the interfaces passed to consumers. The sub-node copy constructor sharesnode_base_,node_topics_, and the other interface objects with its parent, and computessub_namespace_/effective_namespace_only on theNodeinstance (rclcpp/src/rclcpp/node.cpp:259-275).Nodeitself prefixes relative names before delegating (rclcpp/include/rclcpp/node_impl.hpp:55-99), whileNodeTopics::create_publisherpasses the raw name and shared base to the factory (rclcpp/src/rclcpp/node_interfaces/node_topics.cpp:43-50). Consequently, a consumer holding onlyNodeBaseInterfaceorNodeTopicsInterfacehas no way to recover the effective namespace.This is the interface-layer problem described in wjwwood's comment, not merely a bad
expand_topic_or_service_namecall inimage_transport. Changing that utility to takerclcpp::Nodewould fix one consumer and make the layering worse. It would still leave lifecycle nodes, custom node-likes, and the existing interface-based APIs inconsistent.Proposed interface
Add a small, non-abusive name-resolution facet:
Nodeshould implement this with the same sub-namespace prefixing and remapping rules it already uses forcreate_publisher,create_subscription, andcreate_service. The context should be per sub-node; the physicalNodeBaseInterfaceshould continue to represent the one underlyingrcl_node_tand should not change the meaning ofget_namespace(). Conflating the physical and effective namespaces would break graph identity, fully-qualified node names, and code that intentionally asks for the physical namespace.The context should be captured by the interface aggregate, not by requiring every consumer to know that a sub-node exists.
NodeInterfacescurrently just takes a tuple of interfaceshared_ptrs (rclcpp/include/rclcpp/node_interfaces/node_interfaces.hpp:43-65, and initialization atdetail/node_interfaces_helpers.hpp:135-150). Add aNodeNameContextInterface::SharedPtrmember toNodeInterfaces, populated from the originating node-like when available. The existing explicit constructor from loose interface pointers cannot infer the sub-namespace; it should accept an explicit context argument or use a documented root-context fallback.For compatibility with consumers that still take individual interfaces:
NodeBaseInterface/NodeTopicsInterfaceoverloads, but document them as root-context APIs when no context is supplied.create_publisher,create_subscription, generic publishers/subscriptions, services/clients, and the action create functions. Prefer a singleNodeInterfaces<...>orNodeNameContextInterfaceparameter over adding another unrelated raw pointer.Node::get_node_*_interface()for a sub-node return a small sub-node-aware view or carry the context separately. ANodeTopicsdecorator can prefix/resolve names before forwarding to the shared root interface without changing the root interface's identity. A decorator is preferable to adding another virtual toNodeBaseInterface, which would be an ABI break and still cannot distinguish two sub-node wrappers that share oneNodeBase.NodeNameContextInterfaceto the aggregate requirements inimage_transport's rollingRequiredInterfaces, rather than revertingimage_transporttorclcpp::Node.This gives three compatibility levels:
NodeInterfaces.Affected call sites
The main paths to update are:
rclcpp/include/rclcpp/create_publisher.hpp:55-71: resolve QoS parameter names and create the publisher through the context.rclcpp/include/rclcpp/create_subscription.hpp:64-81: the same path for subscriptions and QoS overrides.rclcpp/src/rclcpp/node_interfaces/node_topics.cpp:43-50and73-90: create-view naming;resolve_topic_nameat141-145.rclcpp/src/rclcpp/node_interfaces/node_services.cpp:78-82: service resolution.rclcpp/src/rclcpp/node_interfaces/node_graph.cpp:456-460,478-482,500-504,522-526,670-674, and785-789: graph queries currently expand from the physical RCL namespace.rclcpp_action/src/graph.cpp:77-81and122-126, plus the raw-interface overloads inrclcpp_action/include/rclcpp_action/create_server.hpp:58-68and the corresponding client functions.rclcpp/include/rclcpp/node_impl.hpp:73,94,145,161,179,196, and214: keep these as theNodeconvenience methods, but delegate to the same context rather than duplicating prefix rules.rclcpp/src/rclcpp/parameter_event_handler.cpp:238and similar direct uses ofNodeBaseInterface::get_namespace()should be audited; not every use should switch to the effective namespace.Lower-level publisher/subscription/client/service constructors also call
expand_topic_or_service_namefor validation using the RCL node handle's physical namespace (publisher_base.cpp:86-89,subscription_base.cpp:89-92). Those paths are usually reached after the higher layer has resolved the name; they should either accept the context for correct diagnostics or remain explicitly root-oriented rather than guessing.Minimal migration path
NodeNameContextInterfaceand implement it onrclcpp::Node; makeLifecycleNodeprovide the root/effective context it can currently represent.NodeInterfacesto capture the context from a node-like, and add a two-argument constructor for explicit loose-interface aggregation.create_*and graph/action helpers to use the context when it is present.image_transport's aggregate to require the context and add an end-to-end sub-node test foradvertiseCamera.Regression tests should cover relative names under nested sub-nodes, absolute names,
~private substitutions, remaps applied after the sub-namespace prefix, a consumer receivingNodeInterfacesfrom a sub-node, and a consumer using the explicit root-only overload. The important negative test is that a looseNodeBaseInterfacecannot magically infer a calling sub-node's namespace; the API should require an explicit context instead of silently doing the wrong thing.fix: second-round findings from a re-run persona and real setup runs (#…