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

BooleanType with ServerDefault false breaks poorly #82

Closed
lolopinto opened this issue Jul 31, 2020 · 0 comments · Fixed by #1131
Closed

BooleanType with ServerDefault false breaks poorly #82

lolopinto opened this issue Jul 31, 2020 · 0 comments · Fixed by #1131

Comments

@lolopinto
Copy link
Owner

lolopinto commented Jul 31, 2020

BooleanType({ name: "NeedsHelp", serverDefault: false }),

breaks with error

Generating /Users/ola/code/helping-hands-on-ent/src/schema/versions/a1973ac9e252_202073181625_add_users_table.py ... done
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1246, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 588, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type boolean: "%!s(bool=false)"


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "auto_schema/gen_db_schema.py", line 37, in <module>
    r.run()
  File "/Users/ola/code/ent/python/auto_schema/auto_schema/runner.py", line 185, in run
    self._apply_changes(diff)
  File "/Users/ola/code/ent/python/auto_schema/auto_schema/runner.py", line 197, in _apply_changes
    self.upgrade()
  File "/Users/ola/code/ent/python/auto_schema/auto_schema/runner.py", line 251, in upgrade
    self.cmd.upgrade()
  File "/Users/ola/code/ent/python/auto_schema/auto_schema/command.py", line 40, in upgrade
    command.upgrade(self.alembic_cfg, revision)
  File "/usr/local/lib/python3.7/site-packages/alembic/command.py", line 276, in upgrade
    script.run_env()
  File "/usr/local/lib/python3.7/site-packages/alembic/script/base.py", line 475, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/usr/local/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 90, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/local/lib/python3.7/site-packages/alembic/util/compat.py", line 156, 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 "/Users/ola/code/ent/python/auto_schema/auto_schema/env.py", line 137, in <module>
    run_migrations_online()
  File "/Users/ola/code/ent/python/auto_schema/auto_schema/env.py", line 130, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/local/lib/python3.7/site-packages/alembic/runtime/environment.py", line 839, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/usr/local/lib/python3.7/site-packages/alembic/runtime/migration.py", line 361, in run_migrations
    step.migration_fn(**kw)
  File "/Users/ola/code/helping-hands-on-ent/src/schema/versions/a1973ac9e252_202073181625_add_users_table.py", line 34, in upgrade
    sa.PrimaryKeyConstraint('id', name='users_id_pkey')
  File "<string>", line 8, in create_table
  File "<string>", line 3, in create_table
  File "/usr/local/lib/python3.7/site-packages/alembic/operations/ops.py", line 1248, in create_table
    return operations.invoke(op)
  File "/usr/local/lib/python3.7/site-packages/alembic/operations/base.py", line 345, in invoke
    return fn(self, operation)
  File "/usr/local/lib/python3.7/site-packages/alembic/operations/toimpl.py", line 101, in create_table
    operations.impl.create_table(table)
  File "/usr/local/lib/python3.7/site-packages/alembic/ddl/impl.py", line 251, in create_table
    self._exec(schema.CreateTable(table))
  File "/usr/local/lib/python3.7/site-packages/alembic/ddl/impl.py", line 134, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 982, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1044, in _execute_ddl
    compiled,
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1250, in _execute_context
    e, statement, parameters, cursor, context
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1476, in _handle_dbapi_exception
    util.raise_from_cause(sqlalchemy_exception, exc_info)
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 152, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1246, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 588, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type boolean: "%!s(bool=false)"

[SQL: 
CREATE TABLE users (
	id UUID NOT NULL, 
	created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL, 
	updated_at TIMESTAMP WITHOUT TIME ZONE NOT NULL, 
	first_name TEXT NOT NULL, 
	last_name TEXT NOT NULL, 
	email_address TEXT, 
	phone_number TEXT NOT NULL, 
	bio TEXT, 
	can_help BOOLEAN DEFAULT '%%!s(bool=false)' NOT NULL, 
	needs_help BOOLEAN DEFAULT '%%!s(bool=false)' NOT NULL, 
	CONSTRAINT users_id_pkey PRIMARY KEY (id)
)

]
(Background on this error at: http://sqlalche.me/e/9h9h)
2020/07/31 01:16:25 cmd.Run() failed with exit status 1

Current acceptable format is

BooleanType({ name: "NeedsHelp", serverDefault: "false" }),

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

Successfully merging a pull request may close this issue.

1 participant