fsyntax / medusa-plugin-printful

Printful Integration for Medusajs
30 stars 6 forks source link

Printful plugin cannot sync products because of missing id in variant money amount #4

Open a0zzy opened 11 months ago

a0zzy commented 11 months ago

The printful plugin cannot sync or create products because of a missing "id" in variant money type.

Medusa version: 1.15.0 Printful plugin version: 1.5.6 Node.js version: 18.17.1 Database: Postgresql Operating system: Ubuntu 22.04 Server

To reproduce the error, follow the printful plugin setup guide and add a product to printful, then restart medusa and try to sync that product into medusa.

[medusa-plugin-printful]: There appeared an error trying to create 'Sinister Classic Oversized Tee' in Medusa: QueryFailedError: null value in column "id" of relation "product_variant_money_amount" violates not-null constraint at PostgresQueryRunner.query (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async InsertQueryBuilder.execute (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/query-builder/InsertQueryBuilder.js:106:33) at async SubjectExecutor.executeInsertOperations (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/persistence/SubjectExecutor.js:260:42) at async SubjectExecutor.execute (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/persistence/SubjectExecutor.js:92:9) at async EntityPersistExecutor.execute (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/persistence/EntityPersistExecutor.js:140:21) { query: 'INSERT INTO "public"."product_variant_money_amount"("variant_id", "money_amount_id") VALUES ($1, DEFAULT), ($2, DEFAULT), ($3, DEFAULT), ($4, DEFAULT), ($5, DEFAULT), ($6, DEFAULT), ($7, DEFAULT), ($8, DEFAULT), ($9, DEFAULT), ($10, DEFAULT), ($11, DEFAULT), ($12, DEFAULT)', parameters: [ 'variant_01HANA3VG67Y0YGBYTN35CC53K', 'variant_01HANA3VG6QXR8NK3Q3QQYA0EJ', 'variant_01HANA3VG6P7SYW5JB5T3MV4JC', 'variant_01HANA3VG71FDF9S7YB8QX00Q0', 'variant_01HANA3VG78KGPZRGA2T7403DQ', 'variant_01HANA3VG7DSD90QTQ5F84Q6NP', 'variant_01HANA3VG77FH4D8CXY8X2CNWF', 'variant_01HANA3VG8A67MXNG4Q5Z92AB8', 'variant_01HANA3VG84P09JN93XSZNN8CZ', 'variant_01HANA3VG87XXK0RV5SDNXRJKJ', 'variant_01HANA3VG8D1GKZNCR0NRHGJZB', 'variant_01HANA3VG9PV0YKK0F5ADBYXSM' ], driverError: error: null value in column "id" of relation "product_variant_money_amount" violates not-null constraint at /home/**********-backend/htdocs/backend.**********.com/node_modules/pg/lib/client.js:526:17 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async PostgresQueryRunner.query (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:178:25) at async InsertQueryBuilder.execute (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/query-builder/InsertQueryBuilder.js:106:33) at async SubjectExecutor.executeInsertOperations (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/persistence/SubjectExecutor.js:260:42) at async SubjectExecutor.execute (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/persistence/SubjectExecutor.js:92:9) at async EntityPersistExecutor.execute (/home/**********-backend/htdocs/backend.**********.com/node_modules/typeorm/persistence/EntityPersistExecutor.js:140:21) { length: 342, severity: 'ERROR', code: '23502', detail: 'Failing row contains (null, null, variant_01HANA3VG67Y0YGBYTN35CC53K, null, 2023-09-18 23:30:53.552346+00, 2023-09-18 23:30:53.552346+00).', hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: 'public', table: 'product_variant_money_amount', column: 'id', dataType: undefined, constraint: undefined, file: 'execMain.c', line: '1883', routine: 'ExecConstraints' }, length: 342, severity: 'ERROR', code: '23502', detail: 'Failing row contains (null, null, variant_01HANA3VG67Y0YGBYTN35CC53K, null, 2023-09-18 23:30:53.552346+00, 2023-09-18 23:30:53.552346+00).', hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: 'public', table: 'product_variant_money_amount', column: 'id', dataType: undefined, constraint: undefined, file: 'execMain.c', line: '1883', routine: 'ExecConstraints' } Job failed with ID 1: undefined

fsyntax commented 11 months ago

Thanks @CleverCarpet for reaching out - I will look into it in a few hours!

JKincorperated commented 11 months ago

I am also getting the same issue. Same error logs of driverError: error: null value in column "id" of relation "product_variant_money_amount" violates not-null constraint

Medusa version: 1.16.1
Printful plugin version: 1.5.6
Node.js version: v20.7.0
Database: Postgresql
Operating system: Debian arm64
fsyntax commented 10 months ago

Hey everyone, sorry for my late response. I just wanted to let you know that I am now investigating the issue and try to resolve it right away.

cardof commented 10 months ago

Same issue, do yo have a timeline for this?

Cetele commented 10 months ago

I am getting the same problem. do you have news about it?

bring-shrubbery commented 10 months ago

@fsyntax Let us know how it goes :) Also if you need any help I'd be happy to help on this.

fsyntax commented 10 months ago

@bring-shrubbery Thanks for the offer! I'd actually be very glad indeed if someone has the spare time to tackle this. I'm currently on a pretty tight contract deadline wich will be done soon, but until then, sadly, I can't really effectively work on the plugin. Though, I promise you guys that I will pick up here again very soon, and v2 of the plugin will be much better, easier and integrative!

EDIT: related issue (at least I think, have to investigate): https://github.com/medusajs/medusa/issues/5306

Creating variants and prices directly using the ProductService is not supported in versions after 1.16.0

bring-shrubbery commented 10 months ago

Thanks for the tip, I tried to revert my shop to the v1.15.1 but it still happens. I'll make sure to keep you updated on the progress.

Btw, I also don't have much free time for this, so don't expect me to be super responsive.

JKincorperated commented 10 months ago

It appears that in medusa v1.17.3 that they have added it back:

feat(medusa): variant creation with prices in productservice.create

bryareh commented 9 months ago

I tried testing the plugin out with

Medusa version: 1.17.3 Printful plugin version: 1.5.6 Node.js version: 20.1.0 Database: Postgresql Operating system: MacOS Sonoma 14.0

but was unsuccessful.

Was anyone able to get this plugin running? I have been trying but get an error when I try to sync products. Not sure what I'm doing wrong. If someone could please help! Many thanks.

[medusa-plugin-printful]:  Finished scheduling Printful product synchronization jobs.
info:    
Processing job #1

[medusa-plugin-printful]: Processing job #1 - [325840769] BRYAREH
[medusa-plugin-printful]: There appeared an error trying to create 'BRYAREH' in Medusa:  Error: Product options length does not match variant options length. Product has 2 and variant has 0.
    at _loop_1 (bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:1153:23)
    at ProductVariantService.validateVariantsToCreate_ (bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:1173:17)
    at ProductVariantService.<anonymous> (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:237:50)
    at step (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:59:23)
    at Object.next /bryareh/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:40:53)
    at fulfilled (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:31:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'invalid_data',
  code: undefined,
  date: 2023-11-02T16:52:21.796Z
}
Job failed with ID 1: undefined
TypeError: Cannot read properties of undefined (reading 'message')
fsyntax commented 9 months ago

It appears that in medusa v1.17.3 that they have added it back:

feat(medusa): variant creation with prices in productservice.create

Indeed, I was waiting for this fix to be merged. I havent gotten to test it out yet with this fix, but basically it should resolve the error. If someone has got the time to test it Id be glad, otherwise I will do so on the weekend :)

JKincorperated commented 9 months ago

I tried testing the plugin out with

Medusa version: 1.17.3 Printful plugin version: 1.5.6 Node.js version: 20.1.0 Database: Postgresql Operating system: MacOS Sonoma 14.0

but was unsuccessful.

Was anyone able to get this plugin running? I have been trying but get an error when I try to sync products. Not sure what I'm doing wrong. If someone could please help! Many thanks.

[medusa-plugin-printful]:  Finished scheduling Printful product synchronization jobs.
info:    
Processing job #1

[medusa-plugin-printful]: Processing job #1 - [325840769] BRYAREH
[medusa-plugin-printful]: There appeared an error trying to create 'BRYAREH' in Medusa:  Error: Product options length does not match variant options length. Product has 2 and variant has 0.
    at _loop_1 (bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:1153:23)
    at ProductVariantService.validateVariantsToCreate_ (bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:1173:17)
    at ProductVariantService.<anonymous> (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:237:50)
    at step (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:59:23)
    at Object.next /bryareh/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:40:53)
    at fulfilled (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:31:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'invalid_data',
  code: undefined,
  date: 2023-11-02T16:52:21.796Z
}
Job failed with ID 1: undefined
TypeError: Cannot read properties of undefined (reading 'message')

Also just tested with v1.17.3 and am getting the same problem

fsyntax commented 9 months ago

I tried testing the plugin out with Medusa version: 1.17.3 Printful plugin version: 1.5.6 Node.js version: 20.1.0 Database: Postgresql Operating system: MacOS Sonoma 14.0 but was unsuccessful. Was anyone able to get this plugin running? I have been trying but get an error when I try to sync products. Not sure what I'm doing wrong. If someone could please help! Many thanks.

[medusa-plugin-printful]:  Finished scheduling Printful product synchronization jobs.
info:    
Processing job #1

[medusa-plugin-printful]: Processing job #1 - [325840769] BRYAREH
[medusa-plugin-printful]: There appeared an error trying to create 'BRYAREH' in Medusa:  Error: Product options length does not match variant options length. Product has 2 and variant has 0.
    at _loop_1 (bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:1153:23)
    at ProductVariantService.validateVariantsToCreate_ (bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:1173:17)
    at ProductVariantService.<anonymous> (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:237:50)
    at step (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:59:23)
    at Object.next /bryareh/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:40:53)
    at fulfilled (/bryareh-store-dot-com/node_modules/@medusajs/medusa/dist/services/product-variant.js:31:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'invalid_data',
  code: undefined,
  date: 2023-11-02T16:52:21.796Z
}
Job failed with ID 1: undefined
TypeError: Cannot read properties of undefined (reading 'message')

Also just tested with v1.17.3 and am getting the same problem

Thanks for testing this out @JKincorperated! I'll figure if this is still an issue of the change from the medusa core. Will keep you updated!

bring-shrubbery commented 9 months ago

Finally got to test it on my computer too, I get the same error as @JKincorperated

alexookah commented 8 months ago

any updates on this? @JKincorperated

JKincorperated commented 8 months ago

Ask @fsyntax.

alexookah commented 8 months ago

Any idea what's the issue @fsyntax ? It's currently blocking me to test and decide if medusajs is the right decision to handle my e-store.

alexookah commented 8 months ago

I checked the draft PR, tested it and improved a bit the code. It seems now that the products sync correctly. Feel free to check it out! https://github.com/fsyntax/medusa-plugin-printful/pull/8

a0zzy commented 8 months ago

Thank you everyone who contributed their hard to this thread. Amazing work.