Message named pkg/Duration with field builtin_interfaces/Duration is invalid
Nobody has claimed this yet.
- Dominant language
- EmberScript
- Stars
- 26
- Forks
- 68
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 1
Description
Generated by Generative AI
No response
Operating System:
Linux
ROS version or commit hash:
rolling
RMW implementation (if applicable):
No response
RMW Configuration (if applicable):
No response
Client library (if applicable):
No response
'ros2 doctor --report' output
No response
Steps to reproduce issue
- Create a message package
pkgcontaining a message type namedDurationwith a field of typebuiltin_interfaces/Duration. - Compile the workspace and inspect the generated Python code.
- Run mypy tests and flake8
Expected behavior
Message type pkg/Duration should be valid.
Actual behavior
The generated message Python code is invalid:
27: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:87:1: F811 redefinition of unused 'Duration' from line 20
27: class Duration(rosidl_pycommon.interface_base_classes.BaseMessage, metaclass=Metaclass_Duration):
27: ^
27:
27: 1 F811 redefinition of unused 'Duration' from line 20
30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:87:1: error: Name "Duration" already defined (possibly by an import) [no-redef]
30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py: note: In member "__eq__" of class "Duration":
30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:151:27: error: "Duration" has no attribute "header" [attr-defined]
30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:153:25: error: "Duration" has no attribute "data" [attr-defined]
30: Found 3 errors in 1 file (checked 46 source files)
Additional information
Indeed, there are multiple places in the generated code that do:
from a.msg import b
But if the message is named pkg.Duration and the type of one of its fields is builtin_interfaces.Duration, then this import shadows the actual pkg.Duration and the code gets either confused, or even invalid.
I think all usages of from a.msg import b should be replaced by import a.msg; .... a.msg.b in the generated code. This way, the name collisions would not happen.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with a message package containing pkg/Duration and a builtin_interfaces/Duration field, then inspect the generated build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py output. Trace the generator code that produces the conflicting imports, update the generation behavior so the message name is not shadowed, and run the reported mypy and flake8 checks to confirm the generated code is valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100