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

additional_data Causes Admin API to Fail #9681

Closed
mk0y opened this issue Oct 20, 2024 · 4 comments
Closed

additional_data Causes Admin API to Fail #9681

mk0y opened this issue Oct 20, 2024 · 4 comments

Comments

@mk0y
Copy link

mk0y commented Oct 20, 2024

Bug report

Describe the bug

I wanted to extend the product module and followed the docs here: https://docs.medusajs.com/v2/resources/commerce-modules/product/extend.

I added my custom props, like title_de (for titles in German language), and curl works with additional_data. But, when pass the body in the POST request without the additional_data the request will fail.

This also causes admin failing to publish a product saying something like "additional_data" is missing.

System information

Medusa version (including plugins): rc
Node.js version: 20.17.0
Database: Postgres
Operating system: macos
Browser (if relevant): Not relevant, this is backend issue.

Steps to reproduce the behavior

  1. Extend the Product module as explained here.
  2. Make a POST request to create a product WITHOUT additional_data property.
  3. See error {"type":"invalid_data","message":"Invalid request: Field 'additional_data' is required"}

Expected behavior

CRUD operations on products should still function even without additional_data prop.

Code snippets

This request fails:

curl -X POST 'localhost:9000/admin/products' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer '$MY_JWT \
--data '{
    "title": "Shoes",
    "options": [
        {
            "title": "Default option",
            "values": ["Default option value"]
        }
    ]
}'
@olivermrbl
Copy link
Contributor

@mk0y, thanks for the report. We'll look into this tomorrow and revert back. Your expectation of the behavior seems reasonable.

@mk0y
Copy link
Author

mk0y commented Oct 21, 2024

Thanks @olivermrbl, i think it's the problem of middleware, my example:

import { defineMiddlewares } from "@medusajs/medusa";
import { z } from "zod";

export default defineMiddlewares({
  routes: [
    {
      method: "POST",
      matcher: "/admin/products",
      additionalDataValidator: {
        title_de: z.string().nullable(),
        description_de: z.string().nullable(),
      },
    },
    {
      method: "POST",
      matcher: "/admin/products/:id",
      additionalDataValidator: {
        title_de: z.string().nullish(),
        description_de: z.string().nullish(),
      },
    },
  ],
});

Seems that additionalDataValidator isn't allowing anything anymore without additional_data property. Admin panel doesn't know about this so it fails.

@linear linear bot closed this as completed Oct 21, 2024
@mk0y
Copy link
Author

mk0y commented Oct 21, 2024

Unfortunately this issue was closed automatically without being resolved.

@olivermrbl
Copy link
Contributor

@mk0y, this is solved in #9687 and will be part of the next release later today.

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

2 participants