Skip to content

Fixed - Import job fails with SQL 1064 on JSON_EXTRACT reserved-word column (values) - #536

Merged
navneetkumar-pim-webkul merged 2 commits into
2.0from
fix/import-json-column-escape
Jul 1, 2026
Merged

navneetkumar-pim-webkul merged 2 commits into
2.0from
fix/import-json-column-escape

Conversation

@navneetkumar-pim-webkul

Copy link
Copy Markdown
Collaborator

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() builds JSON_UNQUOTE(JSON_EXTRACT(values, '$.common.url_key')), but values is a reserved word in MySQL (and Postgres). Grammar::jsonExtract() interpolated the column name unquoted, so the generated query failed with:

SQLSTATE[42000]: 1064 ... near ', '$.common.url_key')) as attr_value from `pfproducts` where JSON_UNQUOTE(JSON_E...

Fix: back-quote the column in MySQLGrammar::jsonExtract() and double-quote it in PostgresGrammar::jsonExtract(), handling both values and table.values forms. (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?

vendor/bin/pest packages/Webkul/Core/tests/Unit/JsonExtractColumnEscapeTest.php packages/Webkul/DataTransfer

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

  • My pull request requires an update on the documentation repository.

Branch Selection

  • Target Branch: 2.0

Pint

Passed.

Tailwind Reordering

N/A.

…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.
Copilot AI review requested due to automatic review settings July 1, 2026 11:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/Webkul/Core/tests/Unit/JsonExtractColumnEscapeTest.php
@navneetkumar-pim-webkul

Copy link
Copy Markdown
Collaborator Author

Added a Postgres table-qualified column-escaping test as suggested, covering products.values → "products"."values" (parity with the MySQL case).

@navneetkumar-pim-webkul
navneetkumar-pim-webkul merged commit 7d1e8c9 into 2.0 Jul 1, 2026
10 of 12 checks passed
@navneetkumar-pim-webkul
navneetkumar-pim-webkul deleted the fix/import-json-column-escape branch July 1, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants