mavutil: fix type error in cache#1217
Merged
tridge merged 1 commit intoJun 21, 2026
Merged
Conversation
This fixes an error when a connection upgrades from MAVLink v1 to v2:
File ".../mavutil.py", line 98, in add_message
messages[mtype]._instances[instance_value] = msg
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object does not support item assignment
Some messages (e.g. HIGHRES_IMU, RAW_IMU) gain an instance field only
in v2, where the field is a v2-only extension. A message of such a type
received before the v1->v2 switch is cached via the non-instance path,
leaving its ._instances attribute as None. After the switch, the same
type is treated as instanced and add_message assumes ._instances is a
dict, causing the crash.
Guard against ._instances being None and (re)create the dict instead of
erroring out.
tridge
approved these changes
Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes an error when a connection upgrades from MAVLink v1 to v2:
Some messages (e.g. HIGHRES_IMU, RAW_IMU) gain an instance field only in v2, where the field is a v2-only extension. A message of such a type received before the v1->v2 switch is cached via the non-instance path, leaving its ._instances attribute as None. After the switch, the same type is treated as instanced and add_message assumes ._instances is a dict, causing the crash.
Guard against ._instances being None and (re)create the dict instead of erroring out.