Skip to content
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

[Bug]: Second Variation not added to cart if medusa has previous deleted region and deleted price list #10718

Open
zaamx opened this issue Dec 24, 2024 · 1 comment

Comments

@zaamx
Copy link

zaamx commented Dec 24, 2024

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "predeploy": "medusa db:migrate",
    "build": "medusa build && ln -s .medusa/server/public/ public",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.1.3",
    "@medusajs/cli": "2.1.3",
    "@medusajs/framework": "2.1.3",
    "@medusajs/medusa": "2.1.3",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "medusa-payment-manual": "^1.0.25",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.1.3",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  },
  "engines": {
    "node": ">=20"
  },
  "packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}

Node.js version

v20

Database and its version

supabase/postgres:15.6.1.113

Operating system name and version

Ubuntu 2204

Browser name

No response

What happended?

In storefront when added a second item to the cart via the SDk i get a error 500 and the servers logs {
message: 'select "price"."id" as "id", "ps"."id" as "price_set_id", "price"."amount" as "amount", "price"."raw_amount" as "raw_amount", "price"."min_quantity" as "min_quantity", "price"."max_quantity" as "max_quantity", "price"."currency_code" as "currency_code", "price"."rules_count" as "rules_count", "price"."pl_rules_count" as "pl_rules_count", "price"."pl_type" as "price_list_type", "price"."price_list_id" as "price_list_id", COALESCE(price.rules_count, 0) + COALESCE(price.pl_rules_count, 0) as "all_rules_count" from "price_set" as "ps" inner join (select "price"."id" as "id", "price"."amount" as "amount", "price"."raw_amount" as "raw_amount", "price"."min_quantity" as "min_quantity", "price"."max_quantity" as "max_quantity", "price"."currency_code" as "currency_code", "price"."price_set_id" as "price_set_id", "price"."rules_count" as "rules_count", "price"."price_list_id" as "price_list_id", "pl"."rules_count" as "pl_rules_count", "pl"."type" as "pl_type", case when price.price_list_id IS NULL then False else True end as "has_price_list" from "price" as "price" left join "price_rule" as "pr" on "pr"."price_id" = "price"."id" left join "price_list" as "pl" on "pl"."id" = "price"."price_list_id" and "pl"."status" = $1 left join "price_list_rule" as "plr" on "plr"."price_list_id" = "pl"."id" where ("price"."price_list_id" is null and (("pr"."attribute" = $2 and "pr"."value" in ($3)) or ("pr"."attribute" = $4 and "pr"."value" in ($5)) or ("pr"."attribute" = $6 and "pr"."value" in ($7)) or ("pr"."attribute" = $8 and "pr"."value" in ($9)) or ("pr"."attribute" = $10 and ("pr"."operator" = $11 and $12 >= pr.value::numeric) or ("pr"."operator" = $13 and $14 > pr.value::numeric) or ("pr"."operator" = $15 and $16 < pr.value::numeric) or ("pr"."operator" = $17 and $18 <= pr.value::numeric) or ("pr"."operator" = $19 and $20 = pr.value::numeric)) or ("pr"."attribute" = $21 and ("pr"."operator" = $22 and $23 >= pr.value::numeric) or ("pr"."operator" = $24 and $25 > pr.value::numeric) or ("pr"."operator" = $26 and $27 < pr.value::numeric) or ("pr"."operator" = $28 and $29 <= pr.value::numeric) or ("pr"."operator" = $30 and $31 = pr.value::numeric)) or "price"."rules_count" = $32)) or ("price"."price_list_id" is not null and "pl"."deleted_at" is null and ("pl"."starts_at" is null or "pl"."starts_at" <= CURRENT_TIMESTAMP) and ("pl"."ends_at" is null or "pl"."ends_at" >= CURRENT_TIMESTAMP) and ((("plr"."attribute" = $33) and "plr"."value" @> $34 or ("plr"."attribute" = $35) and "plr"."value" @> $36 or ("plr"."attribute" = $37) and "plr"."value" @> $38 or ("plr"."attribute" = $39) and "plr"."value" @> $40 or ("plr"."attribute" = $41) and "plr"."value" @> $42 or ("plr"."attribute" = $43) and "plr"."value" @> $44 or "pl"."rules_count" = $45) and ((("pr"."attribute" = $46 and "pr"."value" in ($47)) or ("pr"."attribute" = $48 and "pr"."value" in ($49)) or ("pr"."attribute" = $50 and "pr"."value" in ($51)) or ("pr"."attribute" = $52 and "pr"."value" in ($53)) or ("pr"."attribute" = $54 and ("pr"."operator" = $55 and $56 >= pr.value::numeric) or ("pr"."operator" = $57 and $58 > pr.value::numeric) or ("pr"."operator" = $59 and $60 < pr.value::numeric) or ("pr"."operator" = $61 and $62 <= pr.value::numeric) or ("pr"."operator" = $63 and $64 = pr.value::numeric)) or ("pr"."attribute" = $65 and ("pr"."operator" = $66 and $67 >= pr.value::numeric) or ("pr"."operator" = $68 and $69 > pr.value::numeric) or ("pr"."operator" = $70 and $71 < pr.value::numeric) or ("pr"."operator" = $72 and $73 <= pr.value::numeric) or ("pr"."operator" = $74 and $75 = pr.value::numeric)) and "price"."rules_count" > $76) or "price"."rules_count" = $77))) group by "price"."id", "pl"."id" having count(pr.attribute) = price.rules_count AND price.price_list_id IS NULL or count(DISTINCT plr.attribute) = pl.rules_count AND price.price_list_id IS NOT NULL) as "price" on "price"."price_set_id" = "ps"."id" where "ps"."id" in ($78, $79) and "price"."currency_code" = $80 and ("price"."min_quantity" <= $81 or "price"."min_quantity" is null) order by "price"."has_price_list" asc, "all_rules_count" desc, "amount" asc - invalid input syntax for type numeric: "reg_01JBK60AXTRWF81C3G2Q92WWJ0"',
name: 'error',
stack: 'error: select "price"."id" as "id", "ps"."id" as "price_set_id", "price"."amount" as "amount", "price"."raw_amount" as "raw_amount", "price"."min_quantity" as "min_quantity", "price"."max_quantity" as "max_quantity", "price"."currency_code" as "currency_code", "price"."rules_count" as "rules_count", "price"."pl_rules_count" as "pl_rules_count", "price"."pl_type" as "price_list_type", "price"."price_list_id" as "price_list_id", COALESCE(price.rules_count, 0) + COALESCE(price.pl_rules_count, 0) as "all_rules_count" from "price_set" as "ps" inner join (select "price"."id" as "id", "price"."amount" as "amount", "price"."raw_amount" as "raw_amount", "price"."min_quantity" as "min_quantity", "price"."max_quantity" as "max_quantity", "price"."currency_code" as "currency_code", "price"."price_set_id" as "price_set_id", "price"."rules_count" as "rules_count", "price"."price_list_id" as "price_list_id", "pl"."rules_count" as "pl_rules_count", "pl"."type" as "pl_type", case when price.price_list_id IS NULL then False else True end as "has_price_list" from "price" as "price" left join "price_rule" as "pr" on "pr"."price_id" = "price"."id" left join "price_list" as "pl" on "pl"."id" = "price"."price_list_id" and "pl"."status" = $1 left join "price_list_rule" as "plr" on "plr"."price_list_id" = "pl"."id" where ("price"."price_list_id" is null and (("pr"."attribute" = $2 and "pr"."value" in ($3)) or ("pr"."attribute" = $4 and "pr"."value" in ($5)) or ("pr"."attribute" = $6 and "pr"."value" in ($7)) or ("pr"."attribute" = $8 and "pr"."value" in ($9)) or ("pr"."attribute" = $10 and ("pr"."operator" = $11 and $12 >= pr.value::numeric) or ("pr"."operator" = $13 and $14 > pr.value::numeric) or ("pr"."operator" = $15 and $16 < pr.value::numeric) or ("pr"."operator" = $17 and $18 <= pr.value::numeric) or ("pr"."operator" = $19 and $20 = pr.value::numeric)) or ("pr"."attribute" = $21 and ("pr"."operator" = $22 and $23 >= pr.value::numeric) or ("pr"."operator" = $24 and $25 > pr.value::numeric) or ("pr"."operator" = $26 and $27 < pr.value::numeric) or ("pr"."operator" = $28 and $29 <= pr.value::numeric) or ("pr"."operator" = $30 and $31 = pr.value::numeric)) or "price"."rules_count" = $32)) or ("price"."price_list_id" is not null and "pl"."deleted_at" is null and ("pl"."starts_at" is null or "pl"."starts_at" <= CURRENT_TIMESTAMP) and ("pl"."ends_at" is null or "pl"."ends_at" >= CURRENT_TIMESTAMP) and ((("plr"."attribute" = $33) and "plr"."value" @> $34 or ("plr"."attribute" = $35) and "plr"."value" @> $36 or ("plr"."attribute" = $37) and "plr"."value" @> $38 or ("plr"."attribute" = $39) and "plr"."value" @> $40 or ("plr"."attribute" = $41) and "plr"."value" @> $42 or ("plr"."attribute" = $43) and "plr"."value" @> $44 or "pl"."rules_count" = $45) and ((("pr"."attribute" = $46 and "pr"."value" in ($47)) or ("pr"."attribute" = $48 and "pr"."value" in ($49)) or ("pr"."attribute" = $50 and "pr"."value" in ($51)) or ("pr"."attribute" = $52 and "pr"."value" in ($53)) or ("pr"."attribute" = $54 and ("pr"."operator" = $55 and $56 >= pr.value::numeric) or ("pr"."operator" = $57 and $58 > pr.value::numeric) or ("pr"."operator" = $59 and $60 < pr.value::numeric) or ("pr"."operator" = $61 and $62 <= pr.value::numeric) or ("pr"."operator" = $63 and $64 = pr.value::numeric)) or ("pr"."attribute" = $65 and ("pr"."operator" = $66 and $67 >= pr.value::numeric) or ("pr"."operator" = $68 and $69 > pr.value::numeric) or ("pr"."operator" = $70 and $71 < pr.value::numeric) or ("pr"."operator" = $72 and $73 <= pr.value::numeric) or ("pr"."operator" = $74 and $75 = pr.value::numeric)) and "price"."rules_count" > $76) or "price"."rules_count" = $77))) group by "price"."id", "pl"."id" having count(pr.attribute) = price.rules_count AND price.price_list_id IS NULL or count(DISTINCT plr.attribute) = pl.rules_count AND price.price_list_id IS NOT NULL) as "price" on "price"."price_set_id" = "ps"."id" where "ps"."id" in ($78, $79) and "price"."currency_code" = $80 and ("price"."min_quantity" <= $81 or "price"."min_quantity" is null) order by "price"."has_price_list" asc, "all_rules_count" desc, "amount" asc - invalid input syntax for type numeric: "reg_01JBK60AXTRWF81C3G2Q92WWJ0"\n' +
' at Parser.parseErrorMessage (/app/.medusa/server/node_modules/pg-protocol/src/parser.ts:368:69)\n' +
' at Parser.handlePacket (/app/.medusa/server/node_modules/pg-protocol/src/parser.ts:187:21)\n' +
' at Parser.parse (/app/.medusa/server/node_modules/pg-protocol/src/parser.ts:102:30)\n' +
' at Socket. (/app/.medusa/server/node_modules/pg-protocol/src/index.ts:7:48)\n' +
' at Socket.emit (node:events:520:28)\n' +
' at Socket.emit (node:domain:488:12)\n' +
' at addChunk (node:internal/streams/readable:559:12)\n' +
' at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)\n' +
' at Socket.Readable.push (node:internal/streams/readable:390:5)\n' +
' at TCP.onStreamRead (node:internal/stream_base_commons:191:23)\n' +
'⮑ sat /app/.medusa/server/node_modules/@medusajs/core-flows/dist/cart/workflows/refresh-cart-items.js: [refresh-cart-items -> fetch-variants (invoke)]\n' +
'⮑ sat /app/.medusa/server/node_modules/@medusajs/core-flows/dist/cart/workflows/add-to-cart.js: [add-to-cart -> refresh-cart-items-as-step (invoke)]',
length: 134,
severity: 'ERROR',
code: '22P02',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'numeric.c',
line: '6880',
routine: 'set_var_from_str'
}

the region "reg_01JBK60AXTRWF81C3G2Q92WWJ0" was deleted previously
There was also a custom price list, also deleted.

Expected behavior

To add a second item to the cart

Actual behavior

Returns 500 the api and no item its added to the card

Link to reproduction repo

https://github.com/medusajs/medusa-starter-default

@zaamx
Copy link
Author

zaamx commented Dec 24, 2024

More research has done:

The region doesnt exists in the database but a price rule has references to it so i deleted manually

SELECT * FROM price_rule WHERE value = 'reg_01JBK60AXTRWF81C3G2Q92WWJ0';
DELETE FROM price_rule WHERE value = 'reg_01JBK60AXTRWF81C3G2Q92WWJ0';

Also the linked price

SELECT * FROM price WHERE id = 'price_01JEVH29RBYAW12J8TJJ562BWP';
DELETE FROM price WHERE id = 'price_01JEVH29RBYAW12J8TJJ562BWP';

Obviouslly i dont think this its a valid solution but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant