google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
23.18k stars 3.24k forks source link

[python] Missing class in generated code for unions #5692

Open cryptocode opened 4 years ago

cryptocode commented 4 years ago

Below are three fbs files, two of which includes assets.fbs which contains a union. Depending on compilation order, the generated Python code is missing a class.

assets.fbs

union Asset {}

game.fbs

include "assets.fbs";

table GameData {
    asset: Asset;
}
root_type GameData;

player.fbs

include "assets.fbs";

Depending on the compilation order, you'll get either:

Asset.py (INCORRECT, player.fbs is compiled last)

def AssetCreator(unionType, table):
    from flatbuffers.table import Table
    if not isinstance(table, Table):
        return None
    return None

or

Asset.py (CORRECT, player.fbs is compiled first)

class Asset(object):
    NONE = 0

def AssetCreator(unionType, table):
    from flatbuffers.table import Table
    if not isinstance(table, Table):
        return None
    return None

In other words, if player.fbs is compiled last, an invalidAsset.py without the Asset class is generated.

aardappel commented 4 years ago

@rw may know

github-actions[bot] commented 4 years ago

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

github-actions[bot] commented 3 years ago

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

github-actions[bot] commented 3 years ago

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

github-actions[bot] commented 2 years ago

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

github-actions[bot] commented 1 year ago

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] commented 1 year ago

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] commented 7 months ago

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] commented 1 month ago

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.

cryptocode commented 1 month ago

Not stale (unable to add label) - bug still around