saleor / saleor-dashboard

A GraphQL-powered, single-page dashboard application for Saleor.
BSD 3-Clause "New" or "Revised" License
844 stars 1.1k forks source link

Pagination of subcategories: Saleor ran into an unexpected problem #1521

Open gleniat opened 3 years ago

gleniat commented 3 years ago

What I'm trying to achieve

Browse subcategories of a root or parent category.

Steps to reproduce the problem

  1. Dashboard -> Catalog -> Categories -> open any root category with 20+ subcategories in it.
  2. Scroll to subcategories section, first 20 subcategories are shown
  3. Go to the next page (error appears)

What I expected to happen

No errors in dashboard GUI.

Video

2021-10-19_12-19-42-3

HTTP request payload

[
  {
    "operationName": "CategoryDetails",
    "variables": {
      "before": "YXJyYXljb25uZWN0aW9uOjIw",
      "last": 20,
      "id": "Q2F0ZWdvcnk6MTI=",
      "PERMISSION_HANDLE_PAYMENTS": true,
      "PERMISSION_IMPERSONATE_USER": true,
      "PERMISSION_MANAGE_APPS": true,
      "PERMISSION_MANAGE_CHANNELS": true,
      "PERMISSION_MANAGE_CHECKOUTS": true,
      "PERMISSION_MANAGE_DISCOUNTS": true,
      "PERMISSION_MANAGE_GIFT_CARD": true,
      "PERMISSION_MANAGE_MENUS": true,
      "PERMISSION_MANAGE_ORDERS": true,
      "PERMISSION_MANAGE_PAGES": true,
      "PERMISSION_MANAGE_PAGE_TYPES_AND_ATTRIBUTES": true,
      "PERMISSION_MANAGE_PLUGINS": true,
      "PERMISSION_MANAGE_PRODUCTS": true,
      "PERMISSION_MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES": true,
      "PERMISSION_MANAGE_SETTINGS": true,
      "PERMISSION_MANAGE_SHIPPING": true,
      "PERMISSION_MANAGE_STAFF": true,
      "PERMISSION_MANAGE_TRANSLATIONS": true,
      "PERMISSION_MANAGE_USERS": true
    },
    "query": "
      fragment CategoryFragment on Category {
        id
        name
        children {
          totalCount
          __typename
        }
        products {
          totalCount
          __typename
        }
        __typename
      }

      fragment MetadataItem on MetadataItem {
        key
        value
        __typename
      }

      fragment MetadataFragment on ObjectWithMetadata {
        metadata {
          ...MetadataItem
          __typename
        }
        privateMetadata {
          ...MetadataItem
          __typename
        }
        __typename
      }

      fragment CategoryDetailsFragment on Category {
        id
        ...MetadataFragment
        backgroundImage {
          alt
          url
          __typename
        }
        name
        slug
        description
        seoDescription
        seoTitle
        parent {
          id
          __typename
        }
        __typename
      }

      fragment PageInfoFragment on PageInfo {
        endCursor
        hasNextPage
        hasPreviousPage
        startCursor
        __typename
      }

      query CategoryDetails($id: ID!, $first: Int, $after: String, $last: Int, $before: String) {
        category(id: $id) {
          ...CategoryDetailsFragment
          children(first: $first, after: $after, last: $last, before: $before) {
            edges {
              node {
                ...CategoryFragment
                __typename
              }
              __typename
            }
            pageInfo {
              ...PageInfoFragment
              __typename
            }
            __typename
          }
          products(first: $first, after: $after, last: $last, before: $before) {
            pageInfo {
              ...PageInfoFragment
              __typename
            }
            edges {
              cursor
              node {
                id
                name
                thumbnail {
                  url
                  __typename
                }
                __typename
              }
              __typename
            }
            __typename
          }
          __typename
        }
      }
    "
  }
]

HTTP response

[
  {
    "errors": [
      {
        "message": "Expecting value: line 1 column 1 (char 0)",
        "locations": [
          {
            "line": 78,
            "column": 5
          }
        ],
        "path": [
          "category",
          "products"
        ],
        "extensions": {
          "exception": {
            "code": "JSONDecodeError",
            "stacktrace": [
              "Traceback (most recent call last):",
              "  File \"/usr/local/lib/python3.9/site-packages/promise/promise.py\", line 489, in _resolve_from_executor",
              "    executor(resolve, reject)",
              "  File \"/usr/local/lib/python3.9/site-packages/promise/promise.py\", line 756, in executor",
              "    return resolve(f(*args, **kwargs))",
              "  File \"/usr/local/lib/python3.9/site-packages/graphql/execution/middleware.py\", line 75, in make_it_promise",
              "    return next(*args, **kwargs)",
              "  File \"/app/saleor/graphql/core/fields.py\", line 189, in connection_resolver",
              "    return on_resolve(iterable)",
              "  File \"/app/saleor/graphql/core/fields.py\", line 237, in resolve_connection",
              "    connection = super().resolve_connection(",
              "  File \"/app/saleor/graphql/core/fields.py\", line 68, in resolve_connection",
              "    connection = connection_from_queryset_slice(iterable, **common_args)",
              "  File \"/app/saleor/graphql/core/connection.py\", line 241, in connection_from_queryset_slice",
              "    cursor = from_global_cursor(cursor) if cursor else None",
              "  File \"/app/saleor/graphql/core/connection.py\", line 30, in from_global_cursor",
              "    return json.loads(values)",
              "  File \"/usr/local/lib/python3.9/json/__init__.py\", line 346, in loads",
              "    return _default_decoder.decode(s)",
              "  File \"/usr/local/lib/python3.9/json/decoder.py\", line 337, in decode",
              "    obj, end = self.raw_decode(s, idx=_w(s, 0).end())",
              "  File \"/usr/local/lib/python3.9/json/decoder.py\", line 355, in raw_decode",
              "    raise JSONDecodeError(\"Expecting value\", s, err.value) from None",
              "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)"
            ]
          }
        }
      }
    ],
    "data": {
      "category": {
        "id": "Q2F0ZWdvcnk6MTI=",
        "metadata": [],
        "privateMetadata": [],
        "__typename": "Category",
        "backgroundImage": null,
        "name": "01 test root category",
        "slug": "test",
        "description": null,
        "seoDescription": "",
        "seoTitle": "",
        "parent": null,
        "children": {
          "edges": [
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MzY=",
                "name": "testsubcat16",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6Mzc=",
                "name": "testsubcat17",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6Mzg=",
                "name": "testsubcat18",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MTg=",
                "name": "testsubcat01",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6Mzk=",
                "name": "testsubcat19",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6NDA=",
                "name": "testsubcat20",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6NDE=",
                "name": "testsubcat21",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MTk=",
                "name": "testsubcat02",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MjM=",
                "name": "testsubcat03",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MjQ=",
                "name": "testsubcat04",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MjU=",
                "name": "testsubcat05",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MjY=",
                "name": "testsubcat06",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6Mjc=",
                "name": "testsubcat07",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6Mjg=",
                "name": "testsubcat08",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6Mjk=",
                "name": "testsubcat09",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MzA=",
                "name": "testsubcat10",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MzE=",
                "name": "testsubcat11",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MzI=",
                "name": "testsubcat12",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MzM=",
                "name": "testsubcat13",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            },
            {
              "node": {
                "id": "Q2F0ZWdvcnk6MzQ=",
                "name": "testsubcat14",
                "children": {
                  "totalCount": 0,
                  "__typename": "CategoryCountableConnection"
                },
                "products": {
                  "totalCount": 0,
                  "__typename": "ProductCountableConnection"
                },
                "__typename": "Category"
              },
              "__typename": "CategoryCountableEdge"
            }
          ],
          "pageInfo": {
            "endCursor": "YXJyYXljb25uZWN0aW9uOjE5",
            "hasNextPage": false,
            "hasPreviousPage": false,
            "startCursor": "YXJyYXljb25uZWN0aW9uOjA=",
            "__typename": "PageInfo"
          },
          "__typename": "CategoryCountableConnection"
        },
        "products": null
      }
    }
  }
]

System information

Saleor version:

Operating system:

eCzerniak commented 2 years ago

Thank you for reporting this issue, we will fix it. Regards

eCzerniak commented 2 years ago

Task linked: SALEOR-7131 Pagination of Subcategories - an error is shown