diff --git a/graphify/pg_introspect.py b/graphify/pg_introspect.py index 9182ffeae..24567fa18 100644 --- a/graphify/pg_introspect.py +++ b/graphify/pg_introspect.py @@ -1,5 +1,5 @@ from __future__ import annotations -from pathlib import Path +from pathlib import Path, PurePosixPath from graphify.extract import extract_sql @@ -135,7 +135,7 @@ def introspect_postgres(dsn: str | None = None) -> dict: info = psycopg.conninfo.conninfo_to_dict(dsn or "") host = info.get("host", "localhost") dbname = info.get("dbname", "db") - virtual_path = Path(f"postgresql://{host}/{dbname}") + virtual_path = PurePosixPath(f"postgresql://{host}/{dbname}") # Pass virtual path and in-memory DDL content to extract_sql result = extract_sql(virtual_path, content=ddl_string) diff --git a/tests/test_pg_introspect.py b/tests/test_pg_introspect.py index 42ddb9893..a133cdad3 100644 --- a/tests/test_pg_introspect.py +++ b/tests/test_pg_introspect.py @@ -276,3 +276,17 @@ def test_pg_introspect_import_error(): with patch.dict("sys.modules", {"psycopg": None}): with pytest.raises(ImportError, match="psycopg is required"): introspect_postgres("postgresql://localhost/db") + + +def test_pg_introspect_uri_forward_slashes(): + """Assert that the virtual path in postgresql introspection output uses forward slashes on all platforms.""" + mock_psycopg = _make_mock_psycopg([], [], [], [], host="some-host", dbname="some-db") + with patch.dict("sys.modules", {"psycopg": mock_psycopg}): + res = introspect_postgres("postgresql://some-host/some-db") + + # We should have at least the file node + assert len(res["nodes"]) > 0 + for node in res["nodes"]: + assert "\\" not in node["source_file"] + assert "postgresql:/some-host/some-db" in node["source_file"] +