medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.93k stars 2.49k forks source link

[v1.x] - Sales Channels feature is mandatory when retrieving a Product on the Admin API Route ? #8102

Closed adevinwild closed 3 months ago

adevinwild commented 3 months ago

Bug report

Describe the bug

When you disable the sales_channel feature flag, you keep getting errors on the [GET] - /admin/products/:id route. It's because that route still tries to look for product's sales channels, I remember that at a time a check was made using the FF router, but now it seems that it's always there :

// [v1.20.7] - src/api/routes/admin/products/get-product.ts

const shouldSetAvailability =
    req.retrieveConfig.relations?.includes("variants")

  if (shouldSetAvailability) {
    let salesChannels

    if (isMedusaV2FlagOn) {
      const remoteQuery = req.scope.resolve("remoteQuery")
      const query = {
        sales_channel: {
          fields: ["id"],
        },
      }
      salesChannels = await remoteQuery(query)
    } else {
      const salesChannelService: SalesChannelService = req.scope.resolve(
        "salesChannelService"
      )
      ;[salesChannels] = await salesChannelService.listAndCount(
        {},
        { select: ["id"] }
      )
    }

    decoratePromises.push(
      productVariantInventoryService.setProductAvailability(
        [product],
        salesChannels.map((salesChannel) => salesChannel.id)
      )
    )
  }

System information

Medusa version (including plugins): v1.20.7

Steps to reproduce the behavior

  1. Disable the sales_channel feature flag in the Medusa config
  2. Create a product on the Admin UI
  3. Error is throwed in the console :
driverError: error: relation "public.sales_channel" does not exist

Expected behavior

I expect a check with the FF router to check if the sales_channel feature flag is enabled to make sure we don't have this relation error.

sradevski commented 3 months ago

@adevinwild hey thanks for the report! Would you be keen on opening a PR to fix this? Thanks!

adevinwild commented 3 months ago

@adevinwild hey thanks for the report! Would you be keen on opening a PR to fix this? Thanks!

Yes! Will fix this this weekend šŸ™Œ

adevinwild commented 3 months ago

Here is the related PR šŸ™Œ https://github.com/medusajs/medusa/pull/8120