pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

IPython - AttributeError: 'Connection' object has no attribute '_pgcli'

Open klonuo opened this issue 4 months ago • 0 comments

Latest packages, up to date:

In [3]: %pgcli postgresql://localhost/meaurements
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/.local/lib/python3.12/site-packages/pgcli/magic.py:36, in pgcli_line_magic(line)
     34 try:
     35     # A corresponding pgcli object already exists
---> 36     pgcli = conn._pgcli
     37     _logger.debug("Reusing existing pgcli")

AttributeError: 'Connection' object has no attribute '_pgcli'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 get_ipython().run_line_magic('pgcli', 'postgresql://localhost/meaurements')

File ~/.local/lib/python3.12/site-packages/IPython/core/interactiveshell.py:2504, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2502     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2503 with self.builtin_trap:
-> 2504     result = fn(*args, **kwargs)
   2506 # The code below prevents the output from being displayed
   2507 # when using magics with decorator @output_can_be_silenced
   2508 # when the last Python token in the expression is a ';'.
   2509 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/.local/lib/python3.12/site-packages/pgcli/magic.py:43, in pgcli_line_magic(line)
     38 except AttributeError:
     39     # I can't figure out how to get the underylying psycopg2 connection
     40     # from the sqlalchemy connection, so just grab the url and make a
     41     # new connection
     42     pgcli = PGCli()
---> 43     u = conn.session.engine.url
     44     _logger.debug("New pgcli: %r", str(u))
     46     pgcli.connect_uri(str(u._replace(drivername="postgres")))

AttributeError: 'Connection' object has no attribute 'session'

klonuo avatar Aug 29 '25 11:08 klonuo