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
While using Cloud Sql Connector from Google (https://github.com/GoogleCloudPlatform/cloud-sql-python-connector) that is using pg8000 connector for database connections in Flask-SQLAlchamy plugin, faced an issue that we first reported to Google Cloud Platforms (GoogleCloudPlatform/cloud-sql-python-connector#548). After some investigation by them, they concluded it could be a pg8000 issue and advised to create an issue here. Below is more detail to reproduce the error:
The error can be reproduced when trying to connect to GCP Postgresql instances using Flask-SQLAlchemy extension. The code works when trying to use standard python pgsql connectors to GCP Posgtgres instance using TCP connections. When using this library-the Flask-SQLAlchemy extension- pg8000 raises an error on setting the correct field size for a string field (creating a team name), and raises the following error:
manager.dispatch.init_failure(self, args, kwargs)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit
compat.raise_(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
raise exception
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/state.py", line 477, in _initialize_instance
return manager.original_init(*mixed[1:], **kwargs)
File "/home/app/flask/project/models/user.py", line 65, in init
ModelProxy.teams.Team.create(team_name, self)
File "/home/app/flask/project/models/init.py", line 158, in wrapper
value = f(*args, **kwds)
File "/home/app/flask/project/models/teams/team.py", line 68, in create
db.session.commit()
File "", line 2, in commit
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1428, in commit
self._transaction.commit(_to_root=self.future)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 829, in commit
self._prepare_impl()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
self.session.flush()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3345, in flush
self._flush(objects)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3485, in flush
transaction.rollback(capture_exception=True)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit
compat.raise(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise
raise exception
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3445, in _flush
flush_context.execute()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
rec.execute(self)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
util.preloaded.orm_persistence.save_obj(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 244, in save_obj
_emit_insert_statements(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 1221, in _emit_insert_statements
result = connection._execute_20(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1614, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 325, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1481, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1731, in _execute_context
context._set_input_sizes()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 1678, in _set_input_sizes
self.root_connection.handle_dbapi_exception(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2030, in handle_dbapi_exception
util.raise(exc_info[1], with_traceback=exc_info[2])
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise
raise exception
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 1674, in _set_input_sizes
self.dialect.do_set_input_sizes(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/pg8000.py", line 519, in do_set_input_sizes
cursor.setinputsizes(
File "/usr/local/lib/python3.9/site-packages/pg8000/dbapi.py", line 621, in setinputsizes
oid, _ = self._c.py_types[size]
TypeError: cannot unpack non-iterable function object
Flask open source project that is used as a baseline: https://github.com/Sumukh/Ignite
OS type and version: Debian 11
Python version: Python 3.9.15
Connector version: pg8000 installed with: pip install "cloud-sql-python-connector[pg8000]"
Flask-SQLAlchemy extension
As this is still under investigation in Google Cloud Connector side, and I read that it may be an issue there, I am closing this and may re-open if that investigation has more insight on potential source.
Hi @aiscience01, this is indeed a bug in pg8000, thanks for reporting it. It should now be fixed in version 1.29.4. I'll also add a message under the original bug.
Hello,
While using Cloud Sql Connector from Google (https://github.com/GoogleCloudPlatform/cloud-sql-python-connector) that is using pg8000 connector for database connections in Flask-SQLAlchamy plugin, faced an issue that we first reported to Google Cloud Platforms (GoogleCloudPlatform/cloud-sql-python-connector#548). After some investigation by them, they concluded it could be a pg8000 issue and advised to create an issue here. Below is more detail to reproduce the error:
The error can be reproduced when trying to connect to GCP Postgresql instances using Flask-SQLAlchemy extension. The code works when trying to use standard python pgsql connectors to GCP Posgtgres instance using TCP connections. When using this library-the Flask-SQLAlchemy extension- pg8000 raises an error on setting the correct field size for a string field (creating a team name), and raises the following error:
manager.dispatch.init_failure(self, args, kwargs)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit
compat.raise_(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
raise exception
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/state.py", line 477, in _initialize_instance
return manager.original_init(*mixed[1:], **kwargs)
File "/home/app/flask/project/models/user.py", line 65, in init
ModelProxy.teams.Team.create(team_name, self)
File "/home/app/flask/project/models/init.py", line 158, in wrapper
value = f(*args, **kwds)
File "/home/app/flask/project/models/teams/team.py", line 68, in create
db.session.commit()
File "", line 2, in commit
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1428, in commit
self._transaction.commit(_to_root=self.future)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 829, in commit
self._prepare_impl()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
self.session.flush()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3345, in flush
self._flush(objects)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3485, in flush
transaction.rollback(capture_exception=True)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit
compat.raise(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise
raise exception
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 3445, in _flush
flush_context.execute()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
rec.execute(self)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
util.preloaded.orm_persistence.save_obj(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 244, in save_obj
_emit_insert_statements(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 1221, in _emit_insert_statements
result = connection._execute_20(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1614, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 325, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1481, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1731, in _execute_context
context._set_input_sizes()
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 1678, in _set_input_sizes
self.root_connection.handle_dbapi_exception(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2030, in handle_dbapi_exception
util.raise(exc_info[1], with_traceback=exc_info[2])
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise
raise exception
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 1674, in _set_input_sizes
self.dialect.do_set_input_sizes(
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/pg8000.py", line 519, in do_set_input_sizes
cursor.setinputsizes(
File "/usr/local/lib/python3.9/site-packages/pg8000/dbapi.py", line 621, in setinputsizes
oid, _ = self._c.py_types[size]
TypeError: cannot unpack non-iterable function object
Flask open source project that is used as a baseline: https://github.com/Sumukh/Ignite
OS type and version: Debian 11
Python version: Python 3.9.15
Connector version: pg8000 installed with: pip install "cloud-sql-python-connector[pg8000]"
Flask-SQLAlchemy extension
Related Google Connector Github issue: GoogleCloudPlatform/cloud-sql-python-connector#548
The text was updated successfully, but these errors were encountered: