Skip to content

Commit f763327

Browse files
dominusmisheinbergon
authored andcommitted
Fixes #331 - Import all 3rd party modules with an extra _module prefix to avoid collision
1 parent e776bb7 commit f763327

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
@@ -315,7 +315,8 @@ def group_imports(self) -> list[list[str]]:
315315
collection.append(f"from {package} import {imports}")
316316

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

320321
return [
321322
group
@@ -1204,7 +1205,7 @@ def render_column_attribute(self, column_attr: ColumnAttribute) -> str:
12041205
column_python_type = python_type_name
12051206
else:
12061207
python_type_module = python_type.__module__
1207-
column_python_type = f"{python_type_module}.{python_type_name}"
1208+
column_python_type = f"{python_type_module}_module.{python_type_name}"
12081209
self.add_module_import(python_type_module)
12091210
except NotImplementedError:
12101211
self.add_literal_import("typing", "Any")

0 commit comments

Comments
 (0)