Version: graphifyy 0.9.6, Windows.
Description
In graphify/pg_introspect.py, the introspect_postgres() function connects to a PostgreSQL database, retrieves the schema metadata, and formats it as in-memory SQL DDL, which is then parsed by extract_sql().
To serve as a source_file identifier, introspect_postgres() instantiates a virtual URI path using Path:
virtual_path = Path(f"postgresql://{host}/{dbname}")
On Windows, Path parses URI strings as filesystem paths and normalizes them using backslashes (postgresql:\myhost\mydb).
In graphify/extract.py, extract_sql(path: Path) converts this to a string using str(path) (retaining backslashes) and populates the source_file attribute on nodes and edges with this mangled string.
This causes:
- Inconsistent and invalid
source_file values (e.g., postgresql:\myhost\mydb instead of postgresql:/myhost/mydb).
- Test failures in
tests/test_pg_introspect.py::test_pg_introspect_success on Windows due to the backslashes.
Reproduction
On Windows, run the test suite for pg_introspect:
python -m pytest tests/test_pg_introspect.py
This fails with:
E AssertionError: assert 'postgresql:\\myhost\\mydb' == 'postgresql:/myhost/mydb'
E
E - postgresql:/myhost/mydb
E ? ^ ^
E + postgresql:\myhost\mydb
E ? ^ ^
Expected Behavior
The URI path postgresql://host/dbname should always use forward slashes (/), even on Windows.
Root Cause & Location
- In graphify/pg_introspect.py:
virtual_path = Path(f"postgresql://{host}/{dbname}")
Instantiating Path on a URI string is incorrect on Windows.
- In graphify/extract.py:
This should use path.as_posix() if path is a Path instance, or replace backslashes with forward slashes for URI/POSIX normalization.
Version: graphifyy 0.9.6, Windows.
Description
In
graphify/pg_introspect.py, theintrospect_postgres()function connects to a PostgreSQL database, retrieves the schema metadata, and formats it as in-memory SQL DDL, which is then parsed byextract_sql().To serve as a source_file identifier,
introspect_postgres()instantiates a virtual URI path usingPath:On Windows,
Pathparses URI strings as filesystem paths and normalizes them using backslashes (postgresql:\myhost\mydb).In
graphify/extract.py,extract_sql(path: Path)converts this to a string usingstr(path)(retaining backslashes) and populates thesource_fileattribute on nodes and edges with this mangled string.This causes:
source_filevalues (e.g.,postgresql:\myhost\mydbinstead ofpostgresql:/myhost/mydb).tests/test_pg_introspect.py::test_pg_introspect_successon Windows due to the backslashes.Reproduction
On Windows, run the test suite for pg_introspect:
This fails with:
Expected Behavior
The URI path
postgresql://host/dbnameshould always use forward slashes (/), even on Windows.Root Cause & Location
Instantiating
Pathon a URI string is incorrect on Windows.This should use
path.as_posix()ifpathis a Path instance, or replace backslashes with forward slashes for URI/POSIX normalization.