File tree Expand file tree Collapse file tree 5 files changed +18
-54
lines changed
integration-tests/http/__tests__/product/admin
modules/product/src/repositories Expand file tree Collapse file tree 5 files changed +18
-54
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @medusajs/product " : patch
3+ " @medusajs/utils " : patch
4+ ---
5+
6+ fix(product, utils): handle metadata key deletion on product update
Original file line number Diff line number Diff line change @@ -1912,7 +1912,7 @@ medusaIntegrationTestRunner({
19121912
19131913 const payload = {
19141914 metadata : {
1915- "test-key" : "" ,
1915+ "test-key" : "" , // item is deleted by setting to empty string
19161916 "test-key-2" : null ,
19171917 } ,
19181918 }
@@ -1924,13 +1924,11 @@ medusaIntegrationTestRunner({
19241924 )
19251925
19261926 expect ( response . status ) . toEqual ( 200 )
1927- expect ( response . data . product . metadata ) . toEqual (
1928- // BREAKING: Metadata updates are all-or-nothing in v2
1929- {
1930- "test-key" : "" ,
1931- "test-key-2" : null ,
1932- }
1933- )
1927+ expect ( response . data . product . metadata ) . toEqual ( {
1928+ // "test-key" is deleted
1929+ "test-key-2" : null , // updated
1930+ "test-key-3" : "test-value-3" , // preserved
1931+ } )
19341932 } )
19351933
19361934 it ( "updates products sales channels" , async ( ) => {
Original file line number Diff line number Diff line change @@ -72,7 +72,6 @@ export * from "./resolve-exports"
7272export * from "./rules"
7373export * from "./selector-constraints-to-string"
7474export * from "./serialize-error"
75- export * from "./set-metadata"
7675export * from "./simple-hash"
7776export * from "./string-to-select-relation-object"
7877export * from "./stringify-circular"
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 66 buildQuery ,
77 DALUtils ,
88 MedusaError ,
9+ isPresent ,
10+ mergeMetadata ,
911} from "@medusajs/framework/utils"
1012import { SqlEntityManager , wrap } from "@mikro-orm/postgresql"
1113
@@ -148,6 +150,10 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory(
148150 )
149151 }
150152
153+ if ( isPresent ( productToUpdate . metadata ) ) {
154+ productToUpdate . metadata = mergeMetadata ( product . metadata ?? { } , productToUpdate . metadata )
155+ }
156+
151157 wrappedProduct . assign ( productToUpdate )
152158 }
153159
You can’t perform that action at this time.
0 commit comments