sqlacodegen icon indicating copy to clipboard operation
sqlacodegen copied to clipboard

Import all 3rd party modules with an extra `_module` prefix

Open dominusmi opened this issue 8 months ago • 0 comments

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

dominusmi avatar Jun 06 '24 12:06 dominusmi