Repository navigation
Fixed - Import job fails with SQL 1064 on JSON_EXTRACT reserved-word column (values) - #536
Merged
Merged
Conversation
…column The product importer builds JSON_EXTRACT(values, '$.common.url_key') where 'values' is a MySQL/Postgres reserved word. jsonExtract() interpolated the column name unquoted, so the query failed with SQLSTATE 1064 during import. Back-quote (MySQL) / double-quote (Postgres) the column name, handling both 'values' and 'table.values' forms.
There was a problem hiding this comment.
Pull request overview
Fixes a regression on the 2.0 branch where JSON extraction SQL could fail when the JSON column name is a SQL reserved word (notably values), by ensuring the column identifier is properly quoted for both MySQL and Postgres grammars. This unblocks product imports that preload unique attribute values via JSON_EXTRACT/->> expressions.
Changes:
- Quote dot-qualified column identifiers in
MySQLGrammar::jsonExtract()using backticks. - Quote dot-qualified column identifiers in
PostgresGrammar::jsonExtract()using double quotes. - Add unit tests asserting reserved-word column escaping behavior for both drivers (and table-qualified for MySQL).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/Webkul/Core/src/Helpers/Database/Grammars/MySQLGrammar.php | Wraps dot-separated identifier parts in backticks before embedding in JSON_EXTRACT(...). |
| packages/Webkul/Core/src/Helpers/Database/Grammars/PostgresGrammar.php | Wraps dot-separated identifier parts in double quotes before building ->/->> JSON access expressions. |
| packages/Webkul/Core/tests/Unit/JsonExtractColumnEscapeTest.php | Adds coverage ensuring reserved-word column names are correctly escaped in generated JSON extraction SQL. |
Collaborator
Author
|
Added a Postgres table-qualified column-escaping test as suggested, covering |
1 task done
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue Reference
Import job fails immediately with a MySQL 1064 syntax error during product URL-key / attribute JSON extraction.
Description
The product importer's
loadUniqueValuesForPath()buildsJSON_UNQUOTE(JSON_EXTRACT(values, '$.common.url_key')), butvaluesis a reserved word in MySQL (and Postgres).Grammar::jsonExtract()interpolated the column name unquoted, so the generated query failed with:Fix: back-quote the column in
MySQLGrammar::jsonExtract()and double-quote it inPostgresGrammar::jsonExtract(), handling bothvaluesandtable.valuesforms. (The 2.1 and master branches already escape the column, so they are unaffected — this closes the gap on 2.0.)How To Test This?
New unit tests assert the column is escaped for both drivers; the generated query now runs cleanly (
JSON_EXTRACT(\values`, ...)`). DataTransfer suite (100 tests) passes.Documentation
Branch Selection
Pint
Passed.
Tailwind Reordering
N/A.