Skip to content

mavutil: fix type error in cache#1217

Merged
tridge merged 1 commit into
ArduPilot:masterfrom
julianoes:fix-add-message-instances-none
Jun 21, 2026
Merged

mavutil: fix type error in cache#1217
tridge merged 1 commit into
ArduPilot:masterfrom
julianoes:fix-add-message-instances-none

Conversation

@julianoes

Copy link
Copy Markdown
Contributor

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.

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 tridge merged commit 56a3bb0 into ArduPilot:master Jun 21, 2026
21 checks passed
@julianoes julianoes deleted the fix-add-message-instances-none branch June 22, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants