sqlacodegen
sqlacodegen copied to clipboard
Import all 3rd party modules with an extra `_module` prefix
This solves an issue which specifically affects the uuid classes (as explained here https://github.com/agronholm/sqlacodegen/issues/331), but can generally affect any conflict in field name vs import.
What this PR do is add the prefix _module
to any third-party imports, so for the case of uuid, it would result in a schema like:
import uuid as uuid_module
[...]
class SomeTable(Base):
uuid: Mapped[uuid_module.uuid] = mapped_column(Uuid)
The third-party modules are used in two locations as can be seen in the compare. A better way to solve this would be to have some mapping instead a set, such as:
{"real module name": "imported as module name"}
but it would require bigger changes - this method works and is simple