Skip to content

Commit 17f6dec

Browse files
committed
Fixes #331 - Import all 3rd party modules with an extra _module prefix to avoid collision
1 parent 2a60532 commit 17f6dec

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/sqlacodegen/generators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ def group_imports(self) -> list[list[str]]:
306306
collection.append(f"from {package} import {imports}")
307307

308308
for module in sorted(self.module_imports):
309-
thirdparty_imports.append(f"import {module}")
309+
# all third-party module references must include a `_module` prefix to avoid collision with field names
310+
thirdparty_imports.append(f"import {module} as {module}_module")
310311

311312
return [
312313
group
@@ -1192,7 +1193,7 @@ def render_column_attribute(self, column_attr: ColumnAttribute) -> str:
11921193
column_python_type = python_type_name
11931194
else:
11941195
python_type_module = python_type.__module__
1195-
column_python_type = f"{python_type_module}.{python_type_name}"
1196+
column_python_type = f"{python_type_module}_module.{python_type_name}"
11961197
self.add_module_import(python_type_module)
11971198
except NotImplementedError:
11981199
self.add_literal_import("typing", "Any")

0 commit comments

Comments
 (0)