apigee / apigee-m10n-drupal

Add monetization features to a Drupal developer portal
https://www.drupal.org/project/apigee_m10n
GNU General Public License v2.0
13 stars 13 forks source link

[Apigee X] Error on purchase rate plan #404

Closed Spooky063 closed 1 year ago

Spooky063 commented 1 year ago

Description

We are currently testing the transition of our solution from Apigee to Apigee X. So I modified the credentials via the module to be able to connect to the new platform (https://www.drupal.org/docs/contributed-modules/apigee-edge/configure-the-connection-to-apigee#configure-credentials-hybrid).

And when I wanted to buy a rate plan, I had an error.

Steps to Reproduce

I logged in (with a user that is a developer), I went to the purchase page of a rate plan /user/{user}/monetization/xproduct/{product}/plan/{plan}/purchase, I saw the form and I click on the "Purchase" button.

But as soon as I click, I get this error:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" LINE 5: WHERE ("node_field_data"."nid" IN ('xxxxxxxx-xxxx-xxxx-xxxx-... ^: SELECT "base_table"."vid" AS "vid", "base_table"."nid" AS "nid" FROM "node" "base_table" INNER JOIN "node_field_data" "node_field_data" ON "node_field_data"."nid" = "base_table"."nid" WHERE ("node_field_data"."nid" IN (:db_condition_placeholder_0)) AND (EXISTS (SELECT "na"."nid" AS "nid" FROM "node_access" "na" WHERE ((("gid" IN (:db_condition_placeholder_1)) AND ("realm" = :db_condition_placeholder_2)) OR (("gid" IN (:db_condition_placeholder_3)) AND ("realm" = :db_condition_placeholder_4)) OR (("gid" IN (:db_condition_placeholder_5, :db_condition_placeholder_6)) AND ("realm" = :db_condition_placeholder_7))) AND ("na"."grant_view" >= :db_condition_placeholder_8) AND ("na"."fallback" = :db_condition_placeholder_9) AND (("base_table"."nid" = "na"."nid")))); [...] in Drupal\Core\Entity\Query\Sql\Query->result() (line 271 of core/lib/Drupal/Core/Entity/Query/Sql/Query.php).

The problem here is that the rate plan identifier is not an integer but a string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

Version Info

Drupal core 9.4.7 Apigee API Catalog 8.x-2.6 Apigee Edge 2.0.5

divya-intelli commented 1 year ago

Hi @Spooky063 , We were not able to replicate the above issue. Please provide the steps to reproduce the issue. Is there any custom code that is triggered when purchasing the rate plan?

Spooky063 commented 1 year ago

Hello,

I will clarify the steps to follow:

Now, when you set a rate plan on this new field and go on the node, the link to purchase the rate plan is correctly showing. But when you want to buy this rate plan, I get the error message above.

According to my debugger, the problem is here: Drupal\apigee_edge\Entity\FieldableEdgeEntityBase::validate(). When the code try to execute the line

$violations = $this->getTypedData()->validate();
divya-intelli commented 1 year ago

Hi @Spooky063 ,

I am still not able to replicate the issue. I followed the steps that you have mentioned , I was able to purchase the rate plan, no error was thrown. Can you clear the cache once and try again purchasing the rate plan.

divya-intelli commented 1 year ago

Hi @Spooky063 ,

Closing this issue for now, feel free to reopen if the problem still exists.

asantosnbpo commented 1 year ago

Hi, we noticed that the issue that @Spooky063 is happening using Postgres DB. You don't need to follow the steps mentioned, to be able to replicate this is necessary to go to the Buy API and select any of the available Products (Pricing Details button) to see the details, after clicking on the Purchase Product the error is happening.

I'm trying to find the place where this validation occurs without success.

Here is the error on watchdog:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" LINE 5: ...."status" = '1') AND ("node_field_data"."nid" IN ('xxxxxxxx-... ^: SELECT "base_table"."vid" AS "vid", "base_table"."nid" AS "nid" FROM "node" "base_table" INNER JOIN "node_field_data" "node_field_data" ON "node_field_data"."nid" = "base_table"."nid" WHERE ("node_field_data"."status" = :db_condition_placeholder_0) AND ("node_field_data"."nid" IN (:db_condition_placeholder_1)); Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ) in Drupal\Core\Entity\Query\Sql\Query->result() (line 272 of /app/core/lib/Drupal/Core/Entity/Query/Sql/Query.php).

I tried with the same base code using MySQL DB and works fine.

Spooky063 commented 1 year ago

Hello, indeed I used Postgres during my tests and this is the error I encountered. Let me know if you find a solution.

asantosnbpo commented 1 year ago

I just validated with Drupal 8.9.20, Drupal 9.3.2 and the error is the same (is not working with Postgres) @divya-intelli can we reopen the issue?

On my side, I'm trying to find the fix. If I find something I will share via Pull Request so you can review too

Thanks!

divya-intelli commented 1 year ago

Thank you @asantosnbpo for validating. We are looking into this issue. Feel free to create a PR for this.

asantosnbpo commented 1 year ago

Once we applied the patch on Drupal 8.9.20 and Drupal 9.3.2 both using Postgres DB works as expected.

Thanks for the effort