Fix invalid virtual postgres source_file URI backslashes on Windows (#1672)

This commit is contained in:
raman118
2026-07-05 10:42:09 +01:00
committed by safishamsi
parent 1288a557e3
commit 5ffa921e27
2 changed files with 16 additions and 2 deletions
+2 -2
View File
@@ -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)
+14
View File
@@ -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"]