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: The provided ID type is not checked #15466

Open
IKarbowiak opened this issue Feb 23, 2024 · 0 comments
Open

Bug: The provided ID type is not checked #15466

IKarbowiak opened this issue Feb 23, 2024 · 0 comments

Comments

@IKarbowiak
Copy link
Member

What are you trying to achieve?

When an ID type input is not the id of the main object on which the changes are applied and to which Meta.object_type refers to, the type of return ID node is not checked.

Examples:

That's only two but we can find plenty of them.
In such a scenario when an object of a different type is provided, the unhandled error is raised.

Related issue: #13698

Steps to reproduce the problem

  1. Run createProdduct mutation with the product id provided as productType:
    mutation createProduct(
        $productTypeId: ID!,
        $categoryId: ID!
        $name: String!)
    {
        productCreate(
            input: {
                category: $categoryId,
                productType: $productTypeId,
                name: $name,
            })
        {
            product {
                id
                name
                slug
                rating
                category {
                    name
                }
                productType {
                    name
                }
            }
            errors {
                message
                field
            }
        }
    }
  1. See an unhandled error
    raise ValueError(
ValueError: Cannot assign "<saleor.product.models.Product(pk=1, name='Test product')>": "Product.product_type" must be a "ProductType" instance.

What did you expect to happen?

We should introduce a solution to allow providing the required type of the provided ID.
E.g. we can introduce our custom ID scalar that will extend graphene.ID scalar with only_type parameter. Then this parameter will be used when fetching the nodes.

Logs

No response

Environment

Saleor version: all
OS and version: -

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