Skip to content

GraphQl: Fix limit of nested edge field applied only to first parent - #354

Draft
BigRoy wants to merge 2 commits into
developfrom
bugfix/graphql-nested-limit-per-parent
Draft

GraphQl: Fix limit of nested edge field applied only to first parent#354
BigRoy wants to merge 2 commits into
developfrom
bugfix/graphql-nested-limit-per-parent

Conversation

@BigRoy

@BigRoy BigRoy commented Sep 12, 2026

Copy link
Copy Markdown
Member

Bug

A limit set on a nested edge field (e.g. at most 1 link per version) is applied only to the first parent item. All following parents get no nested items.

On a local server with links limited to 1 for 5 versions (four of them have 793 links):

  • develop: [1, 0, 0, 0, 0]
  • this PR: [1, 1, 1, 1, 1]

Cause

The nested field keeps _fetched_counter, but it was never reset when the parent moved to its next item (reset_cursor resets only cursor and need_query). After the first parent reached the limit, get_filters computed limit - fetched = 0 (or negative) and sent first: 0 for all other parents.

Fix

  • Reset _fetched_counter in reset_cursor, so the limit is counted per parent item.
  • Never send a page size lower than 1; stopping is already handled by need_query once the limit is reached.

Reproduce

import ayon_api
from ayon_api.graphql_queries import versions_graphql_query

con = ayon_api.get_server_api_connection()
project_name = "<project with version links>"
version_ids = [v["id"] for v in con.get_versions(project_name, fields={"id"})][:5]

query = versions_graphql_query({"id", "links.id"})
query.set_variable_value("projectName", project_name)
query.set_variable_value("versionIds", version_ids)
query.get_field_by_path("project/versions/links").set_limit(1)
print([len(v["links"]) for v in query.query(con)["project"]["versions"]])

Compare with len(con.get_version_links(project_name, version_id)) for the same versions to make sure they do have links.

Testing notes

  • tests/test_graphql_nested_limit.py reproduces it with an in-memory fake server and also checks no first: 0 is sent.

🤖 Generated with Claude Code

BigRoy and others added 2 commits September 13, 2026 00:05
The fetched items counter of a nested edge field was not reset when the
parent item changed. The first parent used up the limit and all other
parents were queried with 'first: 0' (or negative value) and got no
items. Reset the counter with the cursor and never send a page size
lower than 1.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants