mirror of
https://github.com/safishamsi/graphify.git
synced 2026-09-05 13:16:16 +00:00
Fix invalid virtual postgres source_file URI backslashes on Windows (#1672)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user