Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Version history

**UNRELEASED**

- Printed informational dependency messages to ``stderr`` instead of ``stdout``
to prevent corrupting generated model code when stdout is redirected
(`#451 <https://github.com/agronholm/sqlacodegen/issues/451>`_; PR by @Rajan-vish)
- **BACKWARD INCOMPATIBLE** The SQLModel generator no longer emits ``t_<tablename>``
``Table`` variables for many-to-many association tables that have a primary key, and
their relationships no longer pass ``secondary`` via ``sa_relationship_kwargs``.
Expand Down
8 changes: 5 additions & 3 deletions src/sqlacodegen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ def main() -> None:
return

if citext:
print(f"Using sqlalchemy-citext {version('sqlalchemy-citext')}")
print(
f"Using sqlalchemy-citext {version('sqlalchemy-citext')}", file=sys.stderr
)

if geoalchemy2:
print(f"Using geoalchemy2 {version('geoalchemy2')}")
print(f"Using geoalchemy2 {version('geoalchemy2')}", file=sys.stderr)

if pgvector:
print(f"Using pgvector {version('pgvector')}")
print(f"Using pgvector {version('pgvector')}", file=sys.stderr)

# Use reflection to fill in the metadata
engine_args = _parse_engine_args(args.engine_arg)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,19 @@ def test_main() -> None:
check=True,
)
assert completed.stdout.decode().strip() == expected_version


def test_cli_stdout_clean_from_informational_messages(db_path: Path) -> None:
completed = subprocess.run(
[
sys.executable,
"-m",
"sqlacodegen",
f"sqlite:///{db_path}",
],
capture_output=True,
text=True,
check=True,
)
assert "Using " not in completed.stdout
assert "from sqlalchemy import" in completed.stdout