-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix:mysql reserved keyword issue #4106
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
Changes from 2 commits
cfcc15d
7a27084
0c03ba4
aee5fa8
8c242a4
e39d0d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |||||||||||
| # See the License for the specific language governing permissions and | ||||||||||||
| # limitations under the License. | ||||||||||||
| """Database schema version check utility.""" | ||||||||||||
|
|
||||||||||||
| from __future__ import annotations | ||||||||||||
|
|
||||||||||||
| import logging | ||||||||||||
|
|
@@ -33,7 +34,7 @@ def _get_schema_version_impl(inspector, connection) -> str: | |||||||||||
| if inspector.has_table("adk_internal_metadata"): | ||||||||||||
| try: | ||||||||||||
| result = connection.execute( | ||||||||||||
| text("SELECT value FROM adk_internal_metadata WHERE key = :key"), | ||||||||||||
| text("SELECT value FROM adk_internal_metadata WHERE `key` = :key"), | ||||||||||||
| {"key": SCHEMA_VERSION_KEY}, | ||||||||||||
| ).fetchone() | ||||||||||||
| if result: | ||||||||||||
|
|
@@ -48,8 +49,7 @@ def _get_schema_version_impl(inspector, connection) -> str: | |||||||||||
| "Failed to query schema version from adk_internal_metadata: %s.", | ||||||||||||
| e, | ||||||||||||
| ) | ||||||||||||
| raise | ||||||||||||
| # Metadata table doesn't exist, check for v0 schema. | ||||||||||||
| raise # Metadata table doesn't exist, check for v0 schema. | ||||||||||||
|
||||||||||||
| raise # Metadata table doesn't exist, check for v0 schema. | |
| raise | |
| # Metadata table doesn't exist, check for v0 schema. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment # Metadata table doesn't exist, check for v0 schema. has been moved to an incorrect location. It correctly describes the logic that follows when the adk_internal_metadata table doesn't exist (i.e., the code path after the if inspector.has_table(...) block). By attaching it to this raise statement inside the except block, it becomes misleading, as this block handles any query exception, not just the table's absence.
Please move the comment back to its original location, on a new line after the if block, to accurately describe the fallback logic for checking the v0 schema.
| raise # Metadata table doesn't exist, check for v0 schema. | |
| raise |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ async def test_new_db_uses_latest_schema(tmp_path): | |
| assert has_metadata_table | ||
| schema_version = await conn.run_sync( | ||
| lambda sync_conn: sync_conn.execute( | ||
| text('SELECT value FROM adk_internal_metadata WHERE key = :key'), | ||
| text('SELECT value FROM adk_internal_metadata WHERE `key` = :key'), | ||
| {'key': _schema_check_utils.SCHEMA_VERSION_KEY}, | ||
| ).scalar_one_or_none() | ||
|
||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of backticks (
`key`) to quote thekeycolumn is specific to MySQL and will cause syntax errors on other SQL databases like PostgreSQL. The pull request description incorrectly states that backticks are part of the SQL-92 standard and work on PostgreSQL; the standard uses double quotes. To ensure database portability, you should use a dialect-aware method for quoting identifiers. Since aninspectorobject is available,inspector.dialect.identifier_preparer.quote()can be used to get the correct quoting for the current database dialect.