AttributeError: 'PGDDLCompiler' object has no attribute 'visit_clause'
See original GitHub issueHi, I have this issue when I try to run upgrade
on a migration that will change length of a VARCHAR
column. This is traceback:
Traceback
/.../env/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
INFO [alembic.runtime.migration] Context impl CockroachDBImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade 57cc0f0c7862 -> 30684b5c7f5a, empty message
Traceback (most recent call last):
File "/.../env/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line 77, in _compiler_dispatch
meth = getter(visitor)
AttributeError: 'PGDDLCompiler' object has no attribute 'visit_clause'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/.../env/lib/python3.7/site-packages/sqlalchemy/ext/compiler.py", line 426, in _wrap_existing_dispatch
return existing_dispatch(element, compiler, **kw)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line 79, in _compiler_dispatch
raise exc.UnsupportedCompilationError(visitor, cls)
sqlalchemy.exc.UnsupportedCompilationError: Compiler <sqlalchemy.dialects.postgresql.base.PGDDLCompiler object at 0x108b3ba90> can't render element of type <class 'sqlalchemy.sql.elements.ClauseElement'>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 26, in <module>
manager.run()
File "/.../env/lib/python3.7/site-packages/flask_script/__init__.py", line 417, in run
result = self.handle(argv[0], argv[1:])
File "/.../env/lib/python3.7/site-packages/flask_script/__init__.py", line 386, in handle
res = handle(*args, **config)
File "/.../env/lib/python3.7/site-packages/flask_script/commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "/.../env/lib/python3.7/site-packages/flask_migrate/__init__.py", line 95, in wrapped
f(*args, **kwargs)
File "/.../env/lib/python3.7/site-packages/flask_migrate/__init__.py", line 280, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "/.../env/lib/python3.7/site-packages/alembic/command.py", line 254, in upgrade
script.run_env()
File "/.../env/lib/python3.7/site-packages/alembic/script/base.py", line 427, in run_env
util.load_python_file(self.dir, 'env.py')
File "/.../env/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 81, in load_python_file
module = load_module_py(module_id, path)
File "/.../env/lib/python3.7/site-packages/alembic/util/compat.py", line 145, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "migrations/env.py", line 88, in <module>
run_migrations_online()
File "migrations/env.py", line 81, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/.../env/lib/python3.7/site-packages/alembic/runtime/environment.py", line 836, in run_migrations
self.get_context().run_migrations(**kw)
File "/.../env/lib/python3.7/site-packages/alembic/runtime/migration.py", line 330, in run_migrations
step.migration_fn(**kw)
File "/.../test/migrations/versions/30684b5c7f5a_.py", line 24, in upgrade
existing_nullable=True)
File "<string>", line 8, in alter_column
File "<string>", line 3, in alter_column
File "/.../env/lib/python3.7/site-packages/alembic/operations/ops.py", line 1444, in alter_column
return operations.invoke(alt)
File "/.../env/lib/python3.7/site-packages/alembic/operations/base.py", line 319, in invoke
return fn(self, operation)
File "/.../env/lib/python3.7/site-packages/alembic/operations/toimpl.py", line 53, in alter_column
**operation.kw
File "/.../env/lib/python3.7/site-packages/alembic/ddl/postgresql.py", line 101, in alter_column
existing_nullable=existing_nullable,
File "/.../env/lib/python3.7/site-packages/alembic/ddl/impl.py", line 115, in _exec
return conn.execute(construct, *multiparams, **params)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 948, in execute
return meth(self, multiparams, params)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1003, in _execute_ddl
if not self.schema_for_object.is_default else None)
File "<string>", line 1, in <lambda>
File "/.../env/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 442, in compile
return self._compiler(dialect, bind=bind, **kw)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/sql/ddl.py", line 26, in _compiler
return dialect.ddl_compiler(dialect, self, **kw)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/sql/compiler.py", line 219, in __init__
self.string = self.process(self.statement, **compile_kwargs)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/sql/compiler.py", line 245, in process
return obj._compiler_dispatch(self, **kwargs)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/ext/compiler.py", line 435, in <lambda>
lambda *arg, **kw: existing(*arg, **kw))
File "/.../env/lib/python3.7/site-packages/sqlalchemy/ext/compiler.py", line 474, in __call__
return fn(element, compiler, **kw)
File "/.../env/lib/python3.7/site-packages/sqlalchemy/ext/compiler.py", line 430, in _wrap_existing_dispatch
"compilation handler." % type(element))
sqlalchemy.exc.CompileError: <class 'alembic.ddl.postgresql.PostgresqlColumnType'> construct has no default compilation handler.
Environment
python: v3.7.0
cockroachdb: v2.1.4
Packages
alembic==1.0.5
cockroachdb==0.3.0
SQLAlchemy==1.2.11
psycopg2==2.7.5
psycopg2-binary==2.7.5
Flask-SQLAlchemy==2.3.2
Note: Adding this line to alembic.ini
doesn’t change anything:
[sqlalchemy.dialects]
cockroachdb = cockroachdb.sqlalchemy.dialect:CockroachDBDialect
Detailed Exception Reproducing Scenario:
- Create these files:
db-docker-compose.yml:
version: "3"
services:
roach1:
image: cockroachdb/cockroach:v2.1.4
command: start --insecure
ports:
- 26257:26257
- 8080:8080
volumes:
- cockroach1-data:/cockroach/cockroach-data
networks:
- roachnet
networks:
roachnet:
driver: bridge
volumes:
cockroach1-data:
setup_db.sh:
#!/usr/bin/env bash
set -ex
docker-compose -f db-docker-compose.yml up -d
docker-compose -f db-docker-compose.yml exec roach1 ./cockroach sql --insecure -e 'DROP DATABASE IF EXISTS testdb'
docker-compose -f db-docker-compose.yml exec roach1 ./cockroach sql --insecure -e 'CREATE DATABASE testdb'
manage.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from sqlalchemy.dialects import postgresql
import cockroachdb
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'cockroachdb://root@localhost:26257/testdb?sslmode=disable'
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
class User(db.Model):
id = db.Column(db.INTEGER, primary_key=True)
name = db.Column(db.VARCHAR(length=64))
if __name__ == '__main__':
manager.run()
-
./setup_db.sh
-
python manage.py db init
(python v3.7.0), and in themigrations/env.py
file, addcompare_type=True
tocontext.configure(...)
arguments, becuase we want alembic compare columns type. -
python manage.py db migrate
, will create this file: migrations/versions/57cc0f0c7862_.py:
"""empty message
Revision ID: 57cc0f0c7862
Revises:
Create Date: 2019-01-27 11:40:29.338727
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '57cc0f0c7862'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('user',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('name', sa.VARCHAR(length=64), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user')
# ### end Alembic commands ###
python manage.py db upgrade
, will create the table on DB.- change string column length in the
manage.py
file:name = db.Column(db.VARCHAR(length=128))
python manage.py db migrate
, will create another file: migrations/versions/30684b5c7f5a_.py:
"""empty message
Revision ID: 30684b5c7f5a
Revises: 57cc0f0c7862
Create Date: 2019-01-27 11:41:15.854357
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '30684b5c7f5a'
down_revision = '57cc0f0c7862'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('user', 'name',
existing_type=sa.VARCHAR(length=64),
type_=sa.VARCHAR(length=128),
existing_nullable=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('user', 'name',
existing_type=sa.VARCHAR(length=128),
type_=sa.VARCHAR(length=64),
existing_nullable=True)
# ### end Alembic commands ###
python manage.py db upgrade
. This commnad will produce the exception and will not change the db.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
AttributeError: 'PGDDLCompiler' object has no attribute ...
Hi, I have this issue when I try to run upgrade on a migration that will change length of a VARCHAR column. This...
Read more >Alembic: AttributeError: 'RedshiftDDLCompiler' object has no ...
I have this issue when I try to run upgrade on a migration that will change the type of a VARCHAR column to...
Read more >AttributeError: 'GenericTypeCompiler' object has no attribute ...
Hi All I'm reflecting a postgresql schema and then taking a str() of the column types, It goes well until it hits a...
Read more >[Solved] AttributeError: 'module' object has no attribute
Click here to subscribe - https://www.youtube.com/channel/UCeVMnSShP_Iviwkknt83cww▻Instagram ...
Read more >Why am I getting AttributeError: Object has no attribute?
PYTHON : Why am I getting AttributeError : Object has no attribute ? [ Gift : Animated Search Engine ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mohsenasm – where you able to resolve this?
We just published a new version: https://pypi.org/project/sqlalchemy-cockroachdb/1.3.0/
If you’re able to try it could you let me know if this is fixed?