flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Python --gen-onefile option not respecting include directive

Open sethraymond opened this issue 9 months ago • 3 comments

Found in Version: flatc version 24.12.23

Steps to Reproduce:

  1. Build the following .fbs files:

inc.fbs:

table Foo {
    bar:int;
    baz:float;
}

base.fbs:

include "inc.fbs";
table Message {
    payload:Foo;
}
root_type Message;
  1. Run flatc --python --gen-onefile --gen-object-api -I ./ inc.fbs base.fbs
  • Note that --gen-object-api isn't the broken flag - import errors can still be seen without it, it's just useful for demonstration purposes
  1. Deserialize a populated MessageT object:
from base_generated import MessageT
from inc_generated import FooT
import flatbuffers

payload = FooT()
payload.bar = 42
payload.baz = 12.3
msg = MessageT()
msg.payload = payload
builder = flatbuffers.Builder(0)
builder.Finish(msg.Pack(builder))

MessageT().InitFromPackedBuf(builder.Output())

Expected Behavior Deserializing a MessageT object is supported

Actual Behavior Deserializing the MessageT object throws a NameError because Foo is not defined (not imported from inc_generated.py) in Message.Payload().

sethraymond avatar Feb 27 '25 18:02 sethraymond

@lu-wang-g , it looks like you're the primary maintainer for the Python side of this utility. Is one of the (known?) ramifications of --gen-onefile that include directives are not allowed in FBS files? If so, can the documentation be updated to reflect that requirement?

sethraymond avatar Mar 03 '25 16:03 sethraymond

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Sep 01 '25 20:09 github-actions[bot]

This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.

github-actions[bot] avatar Sep 15 '25 20:09 github-actions[bot]