Closed kirkholmes closed 1 year ago
Thanks, @kirkholmes I will look into supporting JSONs!
@kirkholmes Did you try using VARIANT data type to handle JSON fields? https://docs.snowflake.net/manuals/sql-reference/data-types-semistructured.html#variant
from snowflake.sqlalchemy.custom_types import VARIANT
op.add_column('flicket_ticket_action', sa.Column('data', VARIANT, nullable=True))
@kirillal I did not. The code was actually autogenerated as part of the migration script. I would think there would be a way that if JSON isn't supported that it would swap sa.JSON for something like sa.VARIANT to address it.
To clean up and re-prioritize bugs and feature requests we are closing all issues older than 6 months as of Apr 1, 2023. If there are any issues or feature requests that you would like us to address, please re-create them. For urgent issues, opening a support case with this link Snowflake Community is the fastest way to get a response
Please answer these questions before submitting your issue. Thanks!
What version of Python are you using (
python --version
)? Python 3.7.6What operating system and processor architecture are you using (
python -c 'import platform; print(platform.platform())'
)? Windows-10-10.0.18362-SP0What are the component versions in the environment (
pip list
)?"""new action model
Revision ID: 36c91aa9b3b5 Revises: fe0f77ef3f46 Create Date: 2019-10-20 21:23:05.959617
""" from alembic import op import sqlalchemy as sa
revision identifiers, used by Alembic.
revision = '36c91aa9b3b5' down_revision = 'fe0f77ef3f46' branch_labels = None depends_on = None
def upgrade():
get connection
def downgrade():
DOWNGRADE CAN BE DANGEROUS AND RESULT IN DATA LOST
INFO [alembic.runtime.migration] Context impl SnowflakeImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. INFO [alembic.runtime.migration] Running upgrade -> fe0f77ef3f46, migrations before source code control INFO [alembic.runtime.migration] Running upgrade fe0f77ef3f46 -> 36c91aa9b3b5, new action model Traceback (most recent call last): File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\sql\visitors.py", line 87, in _compiler_dispatch meth = getter(visitor) AttributeError: 'SnowflakeTypeCompiler' object has no attribute 'visit_JSON'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "manage.py", line 31, in
manager.run()
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\flask_script__init.py", line 417, in run
result = self.handle(argv[0], argv[1:])
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\flask_script__init__.py", line 386, in handle
res = handle(*args, **config)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\flask_script\commands.py", line 216, in call
return self.run(*args, kwargs)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\flask_migrate__init__.py", line 95, in wrapped
f(args, kwargs)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\flask_migrate__init__.py", line 280, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\command.py", line 298, in upgrade
script.run_env()
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\script\base.py", line 489, in run_env
util.load_python_file(self.dir, "env.py")
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\util\pyfiles.py", line 98, in load_python_file
module = load_module_py(module_id, path)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\util\compat.py", line 173, in load_module_py
spec.loader.exec_module(module)
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "migrations\env.py", line 91, in
run_migrations_online()
File "migrations\env.py", line 84, in run_migrations_online
context.run_migrations()
File "", line 8, in run_migrations
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\runtime\environment.py", line 846, in run_migrations
self.get_context().run_migrations( kw)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\runtime\migration.py", line 518, in run_migrations
step.migration_fn(kw)
File "C:\Users\kirk\Projects\flicket\migrations\versions\36c91aa9b3b5_new_action_model.py", line 31, in upgrade
op.add_column('flicket_ticket_action', sa.Column('data', sa.JSON(none_as_null=True), nullable=True))
File "", line 8, in add_column
File "", line 3, in add_column
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\operations\ops.py", line 1927, in add_column
return operations.invoke(op)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\operations\base.py", line 374, in invoke
return fn(self, operation)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\operations\toimpl.py", line 132, in add_column
operations.impl.add_column(table_name, column, schema=schema, kw)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\ddl\impl.py", line 237, in add_column
self._exec(base.AddColumn(table_name, column, schema=schema))
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\ddl\impl.py", line 140, in _exec
return conn.execute(construct, multiparams, params)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\engine\base.py", line 988, in execute
return meth(self, multiparams, params)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\sql\ddl.py", line 72, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1043, in _execute_ddl
else None,
File "", line 1, in
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\sql\elements.py", line 462, in compile
return self._compiler(dialect, bind=bind, kw)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\sql\ddl.py", line 29, in _compiler
return dialect.ddl_compiler(dialect, self, kw)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\sql\compiler.py", line 319, in init__
self.string = self.process(self.statement, compile_kwargs)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\sql\compiler.py", line 350, in process
return obj._compiler_dispatch(self, kwargs)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\ext\compiler.py", line 436, in
lambda *arg, *kw: existing(arg, kw),
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\ext\compiler.py", line 478, in call
return fn(element, compiler, kw)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\ddl\base.py", line 116, in visit_add_column
add_column(compiler, element.column, kw),
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\alembic\ddl\base.py", line 219, in add_column
return "ADD COLUMN %s" % compiler.get_column_specification(column, kw)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\snowflake\sqlalchemy\base.py", line 320, in get_column_specification
column.type, typeexpression=column)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\sql\compiler.py", line 400, in process
return type._compiler_dispatch(self, **kw)
File "C:\Users\kirk\Projects\flicket\venv\lib\site-packages\sqlalchemy\sql\visitors.py", line 89, in _compiler_dispatch
raise exc.UnsupportedCompilationError(visitor, cls)
sqlalchemy.exc.UnsupportedCompilationError: Compiler <snowflake.sqlalchemy.base.SnowflakeTypeCompiler object at 0x000001B84E167C08> can't render element of type <class 'sqlalchemy.sql.sqltypes.JSON'>
import logging import os
for logger_name in ['snowflake.sqlalchemy', 'snowflake.connector', 'botocore']: logger = logging.getLogger(logger_name) logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) ch.setFormatter(logging.Formatter('%(asctime)s - %(threadName)s %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s')) logger.addHandler(ch)