dbcli / dbcli/pgspecial

Bug with cursor initialized from SQLalchemy on PGSpecial

Open
#138 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
86
Forks
55
PR merge metrics
No merged PRs in 30d

Description

Hello, I noticed one issue after upgrading pgspecial to 2.1.0.

The issue is I used sqlalchemy to construct my connection,

Following code works fine in pgspecial.2.0.1, but not 2.1.0 version

Way to reproduce the issue:
```
from sqlalchemy import create_engine, text
try:
from pgspecial.main import PGSpecial
except ImportError:
PGSpecial = None
eng = create_engine("YOUR_POSTGRESQL_URL").connect()

pgspecial = PGSpecial()

pgspecial.execute(eng.connection.cursor(), "\d")

```

Trace
```
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line 12
---> 12 pgspecial.execute(eng.connection.cursor(), "\d")

File ~/miniconda3/envs/jupysql/lib/python3.9/site-packages/pgspecial/main.py:116, in PGSpecial.execute(self, cur, sql)
114 return special_cmd.handler()
115 elif special_cmd.arg_type == PARSED_QUERY:
--> 116 return special_cmd.handler(cur=cur, pattern=pattern, verbose=verbose)
117 elif special_cmd.arg_type == RAW_QUERY:
118 return special_cmd.handler(cur=cur, query=sql)

File ~/miniconda3/envs/jupysql/lib/python3.9/site-packages/pgspecial/dbcommands.py:894, in describe_table_details(cur, pattern, verbose)
892 # This is a simple \d[+] command. No table name to follow.
893 if not pattern:
--> 894 return list_objects(cur, pattern, verbose, ["r", "p", "v", "m", "S", "f", ""])
896 # This is a \d command. A royal pain in the ass.
897 schema, relname = sql_name_pattern(pattern)

File ~/miniconda3/envs/jupysql/lib/python3.9/site-packages/pgspecial/dbcommands.py:491, in list_objects(cur, pattern, verbose, relkinds)
488 params["table_pattern"] = SQL("")
490 formatted_query = sql.format(**params)
--> 491 log.debug(formatted_query.as_string(cur))
492 cur.execute(formatted_query)
494 if cur.description:

File ~/miniconda3/envs/jupysql/lib/python3.9/site-packages/psycopg/sql.py:80, in Composable.as_string(self, context)
72 """
73 Return the value of the object as string.
74
(...)
77
78 """
79 conn = context.connection if context else None
---> 80 enc = conn_encoding(conn)
81 b = self.as_bytes(context)
82 if isinstance(b, bytes):

File ~/miniconda3/envs/jupysql/lib/python3.9/site-packages/psycopg/_encodings.py:90, in conn_encoding(conn)
87 if not conn or conn.closed:
88 return "utf-8"
---> 90 pgenc = conn.pgconn.parameter_status(b"client_encoding") or b"UTF8"
91 return pg2pyenc(pgenc)

AttributeError: 'psycopg2.extensions.connection' object has no attribute 'pgconn'
```

Versions:
Python 3.9
sqlalchemy-2.0.8

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.