-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Closed
DineshThumma9
wants to merge
6
commits into
google:main
from
DineshThumma9:fix/mysql-reserved-keyword-issue
+18
−7
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfcc15d
fix(sessions): Escape MySQL reserved keyword 'key' in schema queries
DineshThumma9 7a27084
fix(sessions): Escape MySQL reserved keyword 'key' in schema queries …
DineshThumma9 0c03ba4
refactored with more dialect-aware method for quoting identifiers
DineshThumma9 aee5fa8
corrected misplaced comment
DineshThumma9 8c242a4
corrected misplaced comment and linted
DineshThumma9 e39d0d0
Merge branch 'main' into fix/mysql-reserved-keyword-issue
wuliang229 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
@@ -32,8 +33,11 @@ def _get_schema_version_impl(inspector, connection) -> str: | |
| """Gets DB schema version using inspector and connection.""" | ||
| if inspector.has_table("adk_internal_metadata"): | ||
| try: | ||
| key_col = inspector.dialect.identifier_preparer.quote("key") | ||
| 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}, | ||
| ).fetchone() | ||
|
Comment on lines
37
to
42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if result: | ||
|
|
@@ -49,6 +53,7 @@ def _get_schema_version_impl(inspector, connection) -> str: | |
| e, | ||
| ) | ||
| raise | ||
|
|
||
| # Metadata table doesn't exist, check for v0 schema. | ||
| # V0 schema has an 'events' table with an 'actions' column. | ||
| if inspector.has_table("events"): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.