You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'PGDDLCompiler' object has no attribute '_bind_processors' #59
fromasyncpgsaimportPGfromappimportappDB_CONFIG= {
'host': '172.17.0.3',
'port': 5432,
'database': '***',
'user': 'xtpids',
'password': '***',
'min_size': 5,
'max_size': 10,
}
@app.listener('before_server_start')asyncdefinit_db(*args, **kwargs):
# Initializing a db singleton before server startpg=PG()
awaitpg.init(**DB_CONFIG)
app.db=pgreturnapp.db
# Create tables in some scripttables=Base.metadata.tablesforname, tableintables.items():
create_expr=CreateTable(table)
awaitapp.db.execute(create_expr)
The exception
...
File "/home/wonder/PyEnvs/xtpids-BKbQCeJj/lib/python3.6/site-packages/asyncpgsa/pgsingleton.py", line 82, in execute
return await conn.execute(*args, **kwargs)
File "/home/wonder/PyEnvs/xtpids-BKbQCeJj/lib/python3.6/site-packages/asyncpgsa/connection.py", line 105, in execute
script, params = compile_query(script, dialect=self._dialect)
File "/home/wonder/PyEnvs/xtpids-BKbQCeJj/lib/python3.6/site-packages/asyncpgsa/connection.py", line 83, in compile_query
params = _get_keys(compiled)
File "/home/wonder/PyEnvs/xtpids-BKbQCeJj/lib/python3.6/site-packages/asyncpgsa/connection.py", line 43, in _get_keys
processors = compiled._bind_processors
AttributeError: 'PGDDLCompiler' object has no attribute '_bind_processors'
My analysis
In sqlalchemy's source, only SQLCompiler has _bind_processors property.
However create_expr.compile(dialect=asyncpgsa.connection._dialect) generates an instance of type PGDDLCompiler(DDLCompiler), of which SQLCompiler isn't a base class.
Interesting.. I use alembic for all my table creations and migrations, so I havent tested using sqlalchemy migration methods. Would you be willing to write a PR to fix this?
You could try changing the dialect to psycopg dialect (slqalchemys default) and see if that helps: create_pool(dialect=sa.dialects.postgresql.psycopg2)
Closing as no more activity. Please reopen with a comment if this still needs to be looked at for some reason. Currently lacking actionable info for me.
Ive never really used createTable outside of using alembic. So its possible there are just some things that are missing in this library. I would accept a PR that added support for this.
str(query) seems to return incorrect results where there are more complex datatypes, like arrays. sa.Column(ARRAY(TEXT)) results in ARRAY (blatantly incorrect, the correct datatype string is text[])
Traceback (most recent call last):
File "check_revision.py", line 32, in comain
await test_bug()
File "check_revision.py", line 28, in test_bug
await conn.execute(CreateTable(table))
File "/tmp/asyncpgsa/asyncpgsa/connection.py", line 89, in execute
script, params = compile_query(script, dialect=self._dialect)
File "/tmp/asyncpgsa/asyncpgsa/connection.py", line 60, in compile_query
compiled_params = sorted(compiled.params.items())
AttributeError: 'NoneType' object has no attribute 'items'
This error is trivially fixable (check for None), but even after the fix the error originally reported in this issue will manifest.
Activity
nhumrich commentedon Nov 17, 2017
Interesting.. I use alembic for all my table creations and migrations, so I havent tested using sqlalchemy migration methods. Would you be willing to write a PR to fix this?
thedrow commentedon Dec 4, 2017
I can confirm this problem. Happened to me as well.
Is there a suggested fix I should try?
thedrow commentedon Dec 4, 2017
create_expr.compile(dialect=asyncpgsa.connection._dialect)now fails with'PGDialect_pypostgresql' object has no attribute 'dialect'nhumrich commentedon Dec 7, 2017
You could try changing the dialect to psycopg dialect (slqalchemys default) and see if that helps:
create_pool(dialect=sa.dialects.postgresql.psycopg2)http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#module-sqlalchemy.dialects.postgresql.psycopg2
nhumrich commentedon Feb 13, 2018
Closing as no more activity. Please reopen with a comment if this still needs to be looked at for some reason. Currently lacking actionable info for me.
thedrow commentedon Feb 13, 2018
The psycopg2 dialect does not work with asyncpg (at least with asyncpg 0.12.0. I haven't checked other versions).
The problem is the way that psycopg2 outputs query parameters. The default dialect uses
:param. psycopg2 uses{param}or something similar.nhumrich commentedon Feb 13, 2018
Ive never really used createTable outside of using alembic. So its possible there are just some things that are missing in this library. I would accept a PR that added support for this.
Pehat commentedon Mar 26, 2018
I've noticed that
works fine to me. So maybe you just need to cast an SQL expression to string.
WGH- commentedon Jun 5, 2018
str(query)seems to return incorrect results where there are more complex datatypes, like arrays.sa.Column(ARRAY(TEXT))results inARRAY(blatantly incorrect, the correct datatype string istext[])WGH- commentedon Jun 5, 2018
This snippet seems to work better (at least it compiled
ARRAY(TEXT)correctly):WGH- commentedon Jun 6, 2018
DDL is actually broken in many ways.
will result in the following stack trace:
This error is trivially fixable (check for None), but even after the fix the error originally reported in this issue will manifest.
Moreover, DDL is used to be not broken. The snippet above used to work as it is in
asyncpgsa==0.13.0. I bisected the history and found the first bad commit: 75078a4. (here's bisect scripts for reference: https://gist.github.com/WGH-/cb61522716f2555901855121fd35c458)nhumrich commentedon Jun 13, 2018
Thats weird... Not sure why that commit would have broken DDL
nhumrich commentedon Oct 5, 2018
This might be fixed now thanks to #94