Skip to content

Fix inconsistent Python union creator function naming#8981

Open
tmimmanuel wants to merge 1 commit intogoogle:masterfrom
tmimmanuel:fix/python-union-creator-naming-8843
Open

Fix inconsistent Python union creator function naming#8981
tmimmanuel wants to merge 1 commit intogoogle:masterfrom
tmimmanuel:fix/python-union-creator-naming-8843

Conversation

@tmimmanuel
Copy link
Contributor

Summary

Problem

For a union named my_test_union, the generated code produced:

  • Definition: def MyTestUnionCreator(...) (via namer_.Function() → UpperCamel)
  • Call site: my_test_unionCreator(...) (via namer_.Type() → kKeep)

This caused AttributeError: module has no attribute 'my_test_unionCreator'
at runtime when unpacking unions with non-UpperCamel names.

Fix

One-line change in GenUnPackForUnion in src/idl_gen_python.cpp: replaced
namer_.Type(enum_def) with namer_.Function(enum_def).

Test plan

  • New union_name_test.fbs schema with snake_case union name
  • New TestUnionCreatorNaming in py_test.py verifies Pack/UnPack round-trip
  • Verified test fails without the fix (AttributeError) and passes with it
  • CI passes

How to test

cd tests && PYTHONPATH=../python:. python3 -m unittest py_test.TestUnionCreatorNaming -v

@github-actions github-actions bot added python c++ codegen Involving generating code from schema labels Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Inconsistent python generation of union creator types

1 participant