Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #726 from datafold/fix_conn_attrib_postgres
Browse files Browse the repository at this point in the history
'PostgreSQL' object has no attribute '_conn'
  • Loading branch information
dlawin committed Oct 3, 2023
2 parents 943d128 + 33bfbd7 commit 4f2c7aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 1 addition & 2 deletions data_diff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ def main(conf, run, **kw):
)
except Exception as e:
logging.error(e)
if kw["debug"]:
raise
raise


def _data_diff(
Expand Down
6 changes: 3 additions & 3 deletions data_diff/databases/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def create_connection(self):

pg = import_postgresql()
try:
c = pg.connect(**self._args)
self._conn = pg.connect(**self._args)
if SESSION_TIME_ZONE:
c.cursor().execute(f"SET TIME ZONE '{SESSION_TIME_ZONE}'")
return c
self._conn.cursor().execute(f"SET TIME ZONE '{SESSION_TIME_ZONE}'")
return self._conn
except pg.OperationalError as e:
raise ConnectError(*e.args) from e

Expand Down
10 changes: 8 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@

def run_datadiff_cli(*args):
try:
stdout = subprocess.check_output(
[sys.executable, "-m", "data_diff", "--no-tracking"] + list(args), stderr=subprocess.PIPE
p = subprocess.Popen(
[sys.executable, "-m", "data_diff", "--no-tracking"] + list(args),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate()
except subprocess.CalledProcessError as e:
logging.error(e.stderr)
raise
if stderr:
raise Exception(stderr)
return stdout.splitlines()


Expand Down Expand Up @@ -48,6 +53,7 @@ def setUp(self) -> None:
def test_basic(self):
conn_str = CONN_STRINGS[self.db_cls]
diff = run_datadiff_cli(conn_str, self.table_src_name, conn_str, self.table_dst_name)

assert len(diff) == 1

def test_options(self):
Expand Down

0 comments on commit 4f2c7aa

Please sign in to comment.