Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psycopg <class 'IndexError'> tuple index out of range #90

Closed
IlyaSukhanov opened this issue Sep 6, 2018 · 8 comments
Closed

Psycopg <class 'IndexError'> tuple index out of range #90

IlyaSukhanov opened this issue Sep 6, 2018 · 8 comments
Labels

Comments

@IlyaSukhanov
Copy link
Contributor

  File "/var/task/sqlalchemy/engine/default.py", line 412, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/var/task/aws_xray_sdk/ext/psycopg2/patch.py", line 20, in _xray_traced_connect
    dbname = kwargs['dbname'] if 'dbname' in kwargs else re.search(r'dbname=(\S+)\b', args[0]).groups()[0]
@IlyaSukhanov
Copy link
Contributor Author

I'm presuming the host dbname port user extraction logic does not support all the formats of connection strings that psycopg supports.

@IlyaSukhanov
Copy link
Contributor Author

IlyaSukhanov commented Sep 6, 2018

psycopg2.connect() Supports 3 variants of operation:

  1. psycopg2.connect("dbname=test user=postgres password=secret")
  2. psycopg2.connect(dbname="test", user="postgres", password="secret")
  3. psycopg2.connect()

Variant 3 is ok if arguments are passed via env-vars:
Any other connection parameter supported by the client library/server can be passed either in the connection string or as a keyword. The PostgreSQL documentation contains the complete list of the supported parameters. Also note that the same parameters can be passed to the client library using environment variables.

aws-xray-sdk-python does not support variant 3 or mix of variant 2 and 3.

@IlyaSukhanov
Copy link
Contributor Author

It may not be obvious but use of patch_all() or patch of psycopg will cause any code error out and stack trace when opening connection to database. This is quite serious bug.

@haotianw465 haotianw465 added the bug label Sep 7, 2018
@IlyaSukhanov
Copy link
Contributor Author

After some more digging around turns out problem was different but solution remained the same.

Psycopg supports passing of database name both as dbname and as database. SQL Alchemy uses the database variety triggering the bug.
https://github.com/psycopg/psycopg2/blob/master/lib/__init__.py#L96

There may still be a way to use method 3 as described in comment above but its not obvious. And psycopg will error out if there are no arguments on connect. https://github.com/psycopg/psycopg2/blob/master/lib/__init__.py#L122 Maybe if you set port via kwarg / dsn but the rest via env var?

@revmischa
Copy link

Getting this error when database is localhost

@Tankanow
Copy link
Contributor

Is this still an issue or was this solved with 180de75?

@haotianw465
Copy link
Contributor

@Tankanow this is fixed in the commit you mentioned. We will close this issue once the commit is released (which should be soon).

@haotianw465
Copy link
Contributor

The fix is released in 2.2.0 https://pypi.org/project/aws-xray-sdk/. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants