commerce_stripe_update_8103 does not handle database prefix

Created on 26 January 2025, about 1 month ago

Problem/Motivation

Hi,

I am trying to update from commerce_stripe 8.x-1.1 to 8.x-1.2 and I got the following fatal error on commerce_stripe_update_8103 update:

[notice] Update started: commerce_stripe_update_8103
>  [error]  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'commerce_payment_method__card_exp_month.entity_id' in 'WHERE': DELETE FROM "PREFIX_commerce_payment_method__card_exp_month" WHERE bundle = 'credit_card' and EXISTS (SELECT * FROM "PREFIX_commerce_payment_method" WHERE commerce_payment_method__card_exp_month.entity_id = commerce_payment_method.method_id and commerce_payment_method.type = 'stripe_card'); Array

I changed my actual database prefix by PREFIX in the copy/pasted error.

I think direct database queries like:

      $database->query("INSERT INTO {commerce_payment_method__stripe_card_exp_month} SELECT * FROM {commerce_payment_method__card_exp_month} cem WHERE cem.bundle = 'credit_card' and EXISTS (SELECT * FROM {commerce_payment_method} pm WHERE cem.entity_id = pm.method_id and pm.type = 'stripe_card') and NOT EXISTS (SELECT * FROM {commerce_payment_method__stripe_card_exp_month} scem2 WHERE cem.entity_id = scem2.entity_id);");

do not handle database prefix.

Steps to reproduce

Install commerce_stripe 8.x-1.1 on a website with a database prefix. Update to 8.x-1.2.

Proposed resolution

Rewrite the update code to use database insert/update/delete methods with abstraction layer.

Remaining tasks

πŸ› Bug report
Status

Active

Version

1.2

Component

Code

Created by

πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Grimreaper
  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·
  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Subqueries did not get the replacement {} mechanism.

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Patch for Composer usage.

  • Pipeline finished with Success
    about 1 month ago
    Total: 282s
    #407532
  • πŸ‡¬πŸ‡§United Kingdom joehuggans Harrogate, UK

    @grimreaper I just noticed myself earlier that it's possible to get a diff file by clicking on "Plain diff" on the MR, handy feature if it works.

    I've tested this on a new install with a database prefix and was not able to replicate the error with commerce_stripe_update_8103, not sure why.

    However, I tested the patch and tried to db update again and it went through successfully.

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    @joe huggans, thanks for the feedbacks.

    Thanks, I know the diff or patch file from a Gitlab URL. The problem is that the content of this URL will change if the MR is changed, so I need something stable to rely on. And I don't want to commit the patch file locally on my project, in case other projects needs it. So until Gitlab provide the feature to be able to pass the commit ID for the diff in the MR, I will upload patch files (generated from the MR).

    Before running the update 8103, have you ensured that you had payment gateways that will match the conditions at the beginning of the udpate hook?

    On your fresh install, are you starting from commerce_stripe 8.x-1.1, setup payment gateways, then update to 8.x-1.2?

  • πŸ‡¬πŸ‡§United Kingdom joehuggans Harrogate, UK

    Ahh understood yes, thanks. That would be a nice feature to pass the commit ID for the diff though.

    I had Stripe Payment Element enabled previously for the payment gateway plugin, it looks like I should have tested with Stripe Card Element?

    However, I'm having issues creating such a payment gateway, seeing this error -

    An AJAX HTTP error occurred.
    HTTP Result Code: 500
    Debugging information follows.
    Path: /admin/commerce/config/payment-gateways/add?ajax_form=1
    StatusText: error
    ResponseText: The website encountered an unexpected error. Try again later.TypeError: array_map(): Argument #2 ($array) must be of type array, null given in array_map() (line 303 of modules/contrib/commerce/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php). Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\PaymentGatewayBase->buildConfigurationForm() (Line: 16)
    Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OnsitePaymentGatewayBase->buildConfigurationForm() (Line: 170)
    Drupal\commerce_stripe\Plugin\Commerce\PaymentGateway\Stripe->buildConfigurationForm() (Line: 105)
    Drupal\commerce\Plugin\Commerce\InlineForm\PluginConfiguration->buildInlineForm() (Line: 130)
    Drupal\commerce_payment\Form\PaymentGatewayForm->form() (Line: 107)
    Drupal\Core\Entity\EntityForm->buildForm() (Line: 66)
    Drupal\commerce_payment\Form\PaymentGatewayForm->buildForm()
    call_user_func_array() (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 375)
    Drupal\Core\Form\FormBuilder->rebuildForm() (Line: 633)
    Drupal\Core\Form\FormBuilder->processForm() (Line: 326)
    Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    I had "plugin: stripe_payment_element" too. But in "payment_method_types:" I had "credit_card".

    I don't know where this other issue comes from. I am not on a project with stripe or commerce to try to reproduce right now.

  • πŸ‡¬πŸ‡§United Kingdom joehuggans Harrogate, UK

    I'm just trying to help out with testing.

    But I can't replicate the issue, credit_card seems to be the default for the Stripe Payment Element plugin and it isn't causing an error on the update 8103.

    Hopefully someone else can confirm, sorry

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    I'm just trying to help out with testing.

    No worries and huge thanks for that! :)

  • πŸ‡ΊπŸ‡ΈUnited States TomTech

    @grimreaper,

    Thanks for the report!

    Took a minute to setup to circle on this one, as it has been a while since I've used a prefix. :)

    Direct DB queries do support prefix substitution.

    It wasn't possible to write this query using the abstraction layer, because of the subqueries.

    As observed in your MR, the table names were properly wrapped with curly braces to handle prefix substitution, but for the subquery joins, the table.column needed to also be wrapped as {table}.column. (When using an alias, this isn't necessary, but for some SQL statements, aliases can't be used. For those, the full table name must be used.)

    I've reproduced the issue, and the proposed MR resolves it.

    Merging.

    Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States TomTech
  • πŸ‡ΊπŸ‡ΈUnited States TomTech
Production build 0.71.5 2024