Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Add support for nested definitions in Python mcap-protobuf-support #1321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

methylDragon
Copy link

@methylDragon methylDragon commented Jan 26, 2025

Changelog

Bugfix: Support nested message definitions in mcap-protobuf-support

Description

Consider the following Protobuf definition:

message NestedTypeMessage {
  message NestedType {
      string data = 1;
    }

  NestedType nested = 1;
}

Currently the decoder's use of the protobuf.GetMessageClassesForFiles() misses out the inner NestedType definition, causing decoding failures from missing nested descriptors, even though those descriptors would have been populated as part of the encoded file descriptors in an MCAP file.

The error that is raised is something like: FileDescriptorSet for type {schema.name} is missing that schema

This issue persists to an arbitrary level of nesting.

This PR fixes that issue (including for deeply nested definitions) and adds a unit test to prevent regression.

PS:

How soon after merging this will it make it to PyPI?

@methylDragon methylDragon force-pushed the ch3/nested-proto-support branch 2 times, most recently from a90cda9 to 7943adb Compare January 26, 2025 12:23
Signed-off-by: methylDragon <methylDragon@gmail.com>
@methylDragon methylDragon force-pushed the ch3/nested-proto-support branch from 7943adb to e1f655a Compare January 26, 2025 12:25
copybara-service bot pushed a commit to protocolbuffers/protobuf that referenced this pull request Jan 26, 2025
Otherwise downstream callers must explicitly fetch and generate message classes for nested definitions. (For example [here](foxglove/mcap#1321).)

Example:
```
message NestedTypeMessage {
  message NestedType {
      string data = 1;
    }

  NestedType nested = 1;
}
```

Currently `GetMessageClassesForFiles()` will only return `NestedTypeMessage`, but miss `NestedTypeMessage.NestedType` (and any arbitrary level of nested definitions).

This is an unexpected deviation from the comment that says that it will find and resolve all dependencies.

PiperOrigin-RevId: 719854337
copybara-service bot pushed a commit to protocolbuffers/protobuf that referenced this pull request Jan 26, 2025
Otherwise downstream callers must explicitly fetch and generate message classes for nested definitions. (For example [here](foxglove/mcap#1321).)

Example:
```
message NestedTypeMessage {
  message NestedType {
      string data = 1;
    }

  NestedType nested = 1;
}
```

Currently `GetMessageClassesForFiles()` will only return `NestedTypeMessage`, but miss `NestedTypeMessage.NestedType` (and any arbitrary level of nested definitions).

This is an unexpected deviation from the comment that says that it will find and resolve all dependencies.

PiperOrigin-RevId: 719854337
copybara-service bot pushed a commit to protocolbuffers/protobuf that referenced this pull request Jan 26, 2025
Otherwise downstream callers must explicitly fetch and generate message classes for nested definitions. (For example [here](foxglove/mcap#1321).)

Example:
```
message NestedTypeMessage {
  message NestedType {
      string data = 1;
    }

  NestedType nested = 1;
}
```

Currently `GetMessageClassesForFiles()` will only return `NestedTypeMessage`, but miss `NestedTypeMessage.NestedType` (and any arbitrary level of nested definitions).

This is an unexpected deviation from the comment that says that it will find and resolve all dependencies.

PiperOrigin-RevId: 719854337
@methylDragon methylDragon changed the title Add support for nested definitions in Python mcap-protobuf-support BUGFIX: Add support for nested definitions in Python mcap-protobuf-support Jan 27, 2025
)
while nested_descriptions:
nested_desc = nested_descriptions.pop()
nested_messages[nested_desc.full_name] = GetMessageClass(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this not mutate messages directly?

Copy link
Collaborator

@james-rms james-rms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants