flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Flatbuffer python generation failed when nested flatbuffers are used within a child namespace

Open hotwinter opened this issue 1 year ago • 2 comments

Define the following files

namespace test_nested.nested;

file_identifier "TESB";

table B {
  data1:[ubyte];
}

root_type B;
include "B.fbs";
namespace test_nested;

file_identifier "TESA";

table A {
  data2:[ubyte] (force_align: 64, nested_flatbuffer:"nested.B");
}

root_type A;

and generate the python code using flatc --python A.fbs

try including the generated file in a python file errors out when executing

from test_nested import A as a_fbs
Traceback (most recent call last):
    from test_nested.nested.B import nested.B
                                           ^
SyntaxError: invalid syntax

The solution is to change the line in https://github.com/google/flatbuffers/blob/1c514626e83c20fffa8557e75641848e1e15cd5e/src/idl_gen_python.cpp#L1115 to

const std::string unqualified_name = namer_.Type(struct_def);

in order to get the correct naming for import

hotwinter avatar Mar 11 '25 06:03 hotwinter

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 09 '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 23 '25 20:09 github-actions[bot]