ros/ros_comm

rosbag.Bag.read_messages() returns wrong types for identical MD5 hashes

suurjaak opened this issue · 0 comments

If a bag contains message types with identical MD5 hashes, reading from the bag can return message instances with the wrong type for the topic.

Example:

import genpy.dynamic, rosbag

type1 = genpy.dynamic.generate_dynamic("pkg1/Type1", "bool data")["pkg1/Type1"]
type2 = genpy.dynamic.generate_dynamic("pkg2/Type2", "bool data")["pkg2/Type2"]
bag = rosbag.Bag("my.bag", "w")
bag.write("/type1", type1())
bag.write("/type2", type2())
bag.close()

bag = rosbag.Bag("my.bag")
print(bag.get_type_and_topic_info())
for topic, msg, stamp in bag.read_messages():
    print(topic, type(msg))

Output:

TypesAndTopicsTuple(msg_types={'pkg1/Type1': '8b94c1b53db61fb6aed406028ad6332a',
                               'pkg2/Type2': '8b94c1b53db61fb6aed406028ad6332a'},
                    topics={'/type1': TopicTuple(msg_type='pkg1/Type1', message_count=1, connections=1, frequency=None),
                            '/type2': TopicTuple(msg_type='pkg2/Type2', message_count=1, connections=1, frequency=None)})

/type1 <class 'tmpjnx0_4d3._pkg1__Type1'>
/type2 <class 'tmpjnx0_4d3._pkg1__Type1'>

Expected: messages of type pkg2/Type2 in topic "/type2".
Received: messages of type pkg1/Type1 in topic "/type2".