mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
fix: Database reserved keyword issue
The fix will use quotes to escape "key", which is column name in the metadata table. Should work for different database types. Merge https://github.com/google/adk-python/pull/4106 COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/4106 from DineshThumma9:fix/mysql-reserved-keyword-issue e39d0d02f3695d6890bc3267417b5dad58f7e8ee PiperOrigin-RevId: 854411915
This commit is contained in:
committed by
Copybara-Service
parent
2bd984adb3
commit
94d48fce32
@@ -12,6 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
"""Database schema version check utility."""
|
"""Database schema version check utility."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@@ -32,8 +33,11 @@ def _get_schema_version_impl(inspector, connection) -> str:
|
|||||||
"""Gets DB schema version using inspector and connection."""
|
"""Gets DB schema version using inspector and connection."""
|
||||||
if inspector.has_table("adk_internal_metadata"):
|
if inspector.has_table("adk_internal_metadata"):
|
||||||
try:
|
try:
|
||||||
|
key_col = inspector.dialect.identifier_preparer.quote("key")
|
||||||
result = connection.execute(
|
result = connection.execute(
|
||||||
text("SELECT value FROM adk_internal_metadata WHERE key = :key"),
|
text(
|
||||||
|
f"SELECT value FROM adk_internal_metadata WHERE {key_col} = :key"
|
||||||
|
),
|
||||||
{"key": SCHEMA_VERSION_KEY},
|
{"key": SCHEMA_VERSION_KEY},
|
||||||
).fetchone()
|
).fetchone()
|
||||||
if result:
|
if result:
|
||||||
@@ -49,6 +53,7 @@ def _get_schema_version_impl(inspector, connection) -> str:
|
|||||||
e,
|
e,
|
||||||
)
|
)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# Metadata table doesn't exist, check for v0 schema.
|
# Metadata table doesn't exist, check for v0 schema.
|
||||||
# V0 schema has an 'events' table with an 'actions' column.
|
# V0 schema has an 'events' table with an 'actions' column.
|
||||||
if inspector.has_table("events"):
|
if inspector.has_table("events"):
|
||||||
|
|||||||
@@ -51,12 +51,18 @@ async def test_new_db_uses_latest_schema(tmp_path):
|
|||||||
lambda sync_conn: inspect(sync_conn).has_table('adk_internal_metadata')
|
lambda sync_conn: inspect(sync_conn).has_table('adk_internal_metadata')
|
||||||
)
|
)
|
||||||
assert has_metadata_table
|
assert has_metadata_table
|
||||||
schema_version = await conn.run_sync(
|
|
||||||
lambda sync_conn: sync_conn.execute(
|
def get_schema_version(sync_conn):
|
||||||
text('SELECT value FROM adk_internal_metadata WHERE key = :key'),
|
inspector = inspect(sync_conn)
|
||||||
{'key': _schema_check_utils.SCHEMA_VERSION_KEY},
|
key_col = inspector.dialect.identifier_preparer.quote('key')
|
||||||
).scalar_one_or_none()
|
return sync_conn.execute(
|
||||||
)
|
text(
|
||||||
|
f'SELECT value FROM adk_internal_metadata WHERE {key_col} = :key'
|
||||||
|
),
|
||||||
|
{'key': _schema_check_utils.SCHEMA_VERSION_KEY},
|
||||||
|
).scalar_one_or_none()
|
||||||
|
|
||||||
|
schema_version = await conn.run_sync(get_schema_version)
|
||||||
assert schema_version == _schema_check_utils.LATEST_SCHEMA_VERSION
|
assert schema_version == _schema_check_utils.LATEST_SCHEMA_VERSION
|
||||||
|
|
||||||
# Verify events table columns for v1
|
# Verify events table columns for v1
|
||||||
|
|||||||
Reference in New Issue
Block a user