{"id":962,"hash":"f7e53d02b9328d6138c8813e1b4fd5b1d84f74f8d4c85331501f66c9784de4fe","pattern":"ObjectNotExecutableError when executing any SQL query using AsyncEngine","full_message":"I'm using async_engine. When I try to execute anything:\n\nasync with self.async_engine.connect() as con:\n    query = \"SELECT id, name FROM item LIMIT 50;\"\n    result = await con.execute(f\"{query}\")\n\nI'm getting:\n\nException has occurred: ObjectNotExecutableError\nNot an executable object: 'SELECT id, name FROM item LIMIT 50;'\n\nThis question was asked before by user @stilmaniac but it is now deleted from SO.\n\nI found it in Google Search cache, here is copy.\n\nI have the same issue so I'm reasking it, but the original version is below:\n\nI'm trying to create tables from metadata as follows:\n\nBase = declarative_base()\n\nproperties = Table(\n    'properties', Base.metadata,\n    # ...\n    Column('geolocation', Geography(geometry_type='POINT', srid=4326)),\n    # ... \n)\n\nengine = create_async_engine(\"postgresql+asyncpg://user:password@postgres/\")\nasync with engine.begin() as conn:\n    await conn.run_sync(Base.metadata.create_all)\n\nGives me the following error:\n\nsqlalchemy.exc.ObjectNotExecutableError: Not an executable object: 'CREATE INDEX \"idx_properties_geolocation\" ON \"properties\" USING GIST (\"geolocation\")'\n\nConsidering this doc\n\nVersions:\n\nOS: macOS 11.4 ARM\nSQLAlchemy: 1.4.22\nPython: 3.6","ecosystem":"pypi","package_name":"python-3.x","package_version":null,"solution":"As the exception message suggests, the str 'SELECT id, name FROM item LIMIT 50;' is not an executable object.  To make it executable, wrap it with sqlalchemy.text.\n\nfrom sqlalchemy import text\n\nasync with self.async_engine.connect() as con:\n    query = \"SELECT id, name FROM item LIMIT 50;\"\n    result = await con.execute(text(query))\n\nasync.connection.execute requires that its statement argument\n\n[...] is always an object that is in both the ClauseElement and\nExecutable hierarchies, including:\n\nSelect\n\nInsert, Update, Delete\n\nTextClause and TextualSelect\n\nDDL and objects which inherit from DDLElement\n\nThe synchronous connection.execute method permits raw strings, but this is deprecated in v1.4 and has been removed in SQLAlchemy 2.0.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/69490450/objectnotexecutableerror-when-executing-any-sql-query-using-asyncengine","votes":63,"created_at":"2026-04-19T04:52:05.811852+00:00","updated_at":"2026-04-19T04:52:05.811852+00:00"}