Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions backend/tests/benchmark/test_graphql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ def test_query_one_model(exec_async, aio_benchmark, db: InfrahubDatabase, defaul
}
}
"""

gql_params = exec_async(
prepare_graphql_params, db=db, include_mutation=False, include_subscription=False, branch=default_branch
)
default_branch.update_schema_hash()
gql_params = exec_async(prepare_graphql_params, db=db, branch=default_branch)

for _ in range(NBR_WARMUP):
exec_async(
Expand Down Expand Up @@ -123,10 +121,8 @@ def test_query_rel_many(exec_async, aio_benchmark, db: InfrahubDatabase, default
}
}
"""

gql_params = exec_async(
prepare_graphql_params, db=db, include_mutation=False, include_subscription=False, branch=default_branch
)
default_branch.update_schema_hash()
gql_params = exec_async(prepare_graphql_params, db=db, branch=default_branch)

for _ in range(NBR_WARMUP):
exec_async(
Expand Down Expand Up @@ -174,9 +170,8 @@ def test_query_rel_one(exec_async, aio_benchmark, db: InfrahubDatabase, default_
}
"""

gql_params = exec_async(
prepare_graphql_params, db=db, include_mutation=False, include_subscription=False, branch=default_branch
)
default_branch.update_schema_hash()
gql_params = exec_async(prepare_graphql_params, db=db, branch=default_branch)

for _ in range(NBR_WARMUP):
exec_async(
Expand Down Expand Up @@ -223,7 +218,7 @@ def test_query_rel_one(exec_async, aio_benchmark, db: InfrahubDatabase, default_
# """

# gql_params = exec_async(
# prepare_graphql_params, db=db, include_mutation=False, include_subscription=False, branch=default_branch
# prepare_graphql_params, db=db, branch=default_branch
# )
# aio_benchmark(
# graphql,
Expand Down
11 changes: 6 additions & 5 deletions backend/tests/functional/ipam/test_ipam_rebase_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def test_step02_add_delete_prefix(
) -> None:
branch = await create_branch(db=db, branch_name="delete_prefix")

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=registry.default_branch)
gql_params = await prepare_graphql_params(db=db, branch=registry.default_branch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing schema hash refresh before parameter preparation.

This prepare_graphql_params call lacks a preceding default_branch.update_schema_hash() (or registry.default_branch.update_schema_hash()) call, which is inconsistent with the pattern applied throughout this PR. According to the PR objectives, refreshing the schema hash before parameter preparation helps avoid flaky tests and unnecessary schema regenerations.

Apply this change to add the missing call:

+    default_branch = registry.default_branch
+    default_branch.update_schema_hash()
     gql_params = await prepare_graphql_params(db=db, branch=registry.default_branch)

Or if registry.default_branch is guaranteed to be current, explicitly call:

+    registry.default_branch.update_schema_hash()
     gql_params = await prepare_graphql_params(db=db, branch=registry.default_branch)
🤖 Prompt for AI Agents
In backend/tests/functional/ipam/test_ipam_rebase_reconcile.py around line 92,
the call to prepare_graphql_params is missing a prior schema hash refresh;
insert a call to update_schema_hash() on the appropriate branch (e.g.,
registry.default_branch.update_schema_hash() or
default_branch.update_schema_hash()) immediately before awaiting
prepare_graphql_params(db=db, branch=registry.default_branch) so the schema hash
is refreshed consistently with the rest of the PR and avoids flaky tests.

result = await graphql(
schema=gql_params.schema,
source=CREATE_IPPREFIX,
Expand Down Expand Up @@ -145,8 +145,9 @@ async def test_step03_interlinked_prefixes_and_addresses(
client: InfrahubClient,
) -> None:
branch = await create_branch(db=db, branch_name="interlinked")
branch.update_schema_hash()

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=registry.default_branch)
gql_params = await prepare_graphql_params(db=db, branch=registry.default_branch)
result = await graphql(
schema=gql_params.schema,
source=CREATE_IPPREFIX,
Expand All @@ -160,7 +161,7 @@ async def test_step03_interlinked_prefixes_and_addresses(
assert result.data["IpamIPPrefixCreate"]["object"]["id"]
net_10_0_0_0_7_id = result.data["IpamIPPrefixCreate"]["object"]["id"]

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=branch)
gql_params = await prepare_graphql_params(db=db, branch=branch)
result = await graphql(
schema=gql_params.schema,
source=CREATE_IPPREFIX,
Expand All @@ -177,7 +178,7 @@ async def test_step03_interlinked_prefixes_and_addresses(
assert result.data["IpamIPPrefixCreate"]["object"]["id"]
net_10_0_0_0_15_id = result.data["IpamIPPrefixCreate"]["object"]["id"]

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=registry.default_branch)
gql_params = await prepare_graphql_params(db=db, branch=registry.default_branch)
result = await graphql(
schema=gql_params.schema,
source=CREATE_IPPREFIX,
Expand All @@ -194,7 +195,7 @@ async def test_step03_interlinked_prefixes_and_addresses(
assert result.data["IpamIPPrefixCreate"]["object"]["id"]
net_10_10_8_0_22_id = result.data["IpamIPPrefixCreate"]["object"]["id"]

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=branch)
gql_params = await prepare_graphql_params(db=db, branch=branch)
result = await graphql(
schema=gql_params.schema,
source=CREATE_IPADDRESS,
Expand Down
42 changes: 26 additions & 16 deletions backend/tests/functional/ipam/test_ipam_utilization.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async def test_step01_graphql_prefix_pool_utilization(
container = initial_dataset["container"]
prefix_pool = initial_dataset["prefix_pool"]
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=POOL_UTILIZATION_QUERY,
Expand Down Expand Up @@ -234,7 +234,8 @@ async def test_step01_graphql_prefix_pool_utilization(
}
}

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=PREFIX_UTILIZATION_QUERY,
Expand Down Expand Up @@ -263,7 +264,8 @@ async def test_step01_graphql_address_pool_utilization(
):
prefix = initial_dataset["prefix"]
address_pool = initial_dataset["address_pool"]
gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=POOL_UTILIZATION_QUERY,
Expand Down Expand Up @@ -294,7 +296,7 @@ async def test_step01_graphql_address_pool_utilization(
],
}
}
gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=PREFIX_UTILIZATION_QUERY,
Expand Down Expand Up @@ -342,11 +344,12 @@ async def test_step02_branch_utilization(

async def test_step02_graphql_prefix_pool_branch_utilization(
self, db: InfrahubDatabase, default_branch: Branch, branch2: Branch, initial_dataset, step_02_dataset
):
) -> None:
container = initial_dataset["container"]
container_branch = step_02_dataset["container_branch"]
prefix_pool = initial_dataset["prefix_pool"]
gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=POOL_UTILIZATION_QUERY,
Expand Down Expand Up @@ -385,7 +388,8 @@ async def test_step02_graphql_prefix_pool_branch_utilization(
}
} in prefix_details_list

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=branch2)
branch2.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=branch2)
result = await graphql(
schema=gql_params.schema,
source=PREFIX_UTILIZATION_QUERY,
Expand Down Expand Up @@ -414,11 +418,12 @@ async def test_step02_graphql_prefix_pool_branch_utilization(

async def test_step02_graphql_address_pool_branch_utilization(
self, db: InfrahubDatabase, default_branch: Branch, branch2: Branch, initial_dataset, step_02_dataset
):
) -> None:
prefix = initial_dataset["prefix"]
prefix_branch = step_02_dataset["prefix_branch"]
address_pool = initial_dataset["address_pool"]
gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=POOL_UTILIZATION_QUERY,
Expand Down Expand Up @@ -457,7 +462,8 @@ async def test_step02_graphql_address_pool_branch_utilization(
}
} in prefix_details_list

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=branch2)
branch2.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=branch2)
result = await graphql(
schema=gql_params.schema,
source=PREFIX_UTILIZATION_QUERY,
Expand Down Expand Up @@ -520,11 +526,12 @@ async def test_step03_graphql_prefix_pool_delete_utilization(
initial_dataset,
step_02_dataset,
step_03_dataset,
):
) -> None:
container = initial_dataset["container"]
container_branch = step_02_dataset["container_branch"]
prefix_pool = initial_dataset["prefix_pool"]
gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=POOL_UTILIZATION_QUERY,
Expand Down Expand Up @@ -563,7 +570,8 @@ async def test_step03_graphql_prefix_pool_delete_utilization(
}
} in prefix_details_list

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=branch2)
branch2.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=branch2)
result = await graphql(
schema=gql_params.schema,
source=PREFIX_UTILIZATION_QUERY,
Expand Down Expand Up @@ -598,11 +606,12 @@ async def test_step03_graphql_address_pool_delete_utilization(
initial_dataset,
step_02_dataset,
step_03_dataset,
):
) -> None:
prefix = initial_dataset["prefix"]
prefix_branch = step_02_dataset["prefix_branch"]
address_pool = initial_dataset["address_pool"]
gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=POOL_UTILIZATION_QUERY,
Expand Down Expand Up @@ -641,7 +650,8 @@ async def test_step03_graphql_address_pool_delete_utilization(
}
} in prefix_details_list

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=branch2)
branch2.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=branch2)
result = await graphql(
schema=gql_params.schema,
source=PREFIX_UTILIZATION_QUERY,
Expand Down
6 changes: 2 additions & 4 deletions backend/tests/helpers/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ async def graphql_mutation(
account_session: AccountSession | None = None,
) -> ExecutionResult:
branch = branch or await Branch.get_by_name(name="main", db=db)
branch.update_schema_hash()
variables = variables or {}
gql_params = await prepare_graphql_params(
db=db,
include_subscription=False,
include_mutation=True,
branch=branch,
service=service,
account_session=account_session,
Expand All @@ -98,11 +97,10 @@ async def graphql_query(
) -> ExecutionResult:
branch = branch or await Branch.get_by_name(name="main", db=db)
variables = variables or {}
branch.update_schema_hash()

gql_params = await prepare_graphql_params(
db=db,
include_subscription=False,
include_mutation=False,
branch=branch,
service=service,
account_session=account_session,
Expand Down
35 changes: 20 additions & 15 deletions backend/tests/integration/profiles/test_profile_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ async def test_step_01_one_person_no_profile(
async def test_step_02_one_person_add_profile(
self,
db: InfrahubDatabase,
default_branch,
default_branch: Branch,
person_1,
person_profile_1,
):
) -> None:
mutation = """
mutation {
TestingPersonUpdate(data: {id: "%(person_id)s", profiles: [{ id: "%(profile_id)s"}]}) {
Expand All @@ -92,7 +92,8 @@ async def test_step_02_one_person_add_profile(
}
""" % {"person_id": person_1.id, "profile_id": person_profile_1.id}

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=mutation,
Expand Down Expand Up @@ -134,9 +135,9 @@ async def test_step_02_one_person_add_profile(
async def test_step_03_create_person_with_profile(
self,
db: InfrahubDatabase,
default_branch,
default_branch: Branch,
person_profile_1,
):
) -> None:
mutation = """
mutation {
TestingPersonCreate(data: {name: {value: "Apollo"}, profiles: [{ id: "%(profile_id)s"}]}) {
Expand All @@ -161,7 +162,8 @@ async def test_step_03_create_person_with_profile(
}
""" % {"profile_id": person_profile_1.id}

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=mutation,
Expand Down Expand Up @@ -198,10 +200,10 @@ async def test_step_03_create_person_with_profile(
async def test_step_04_update_non_profile_attribute(
self,
db: InfrahubDatabase,
default_branch,
default_branch: Branch,
person_1,
person_profile_1,
):
) -> None:
mutation = """
mutation {
TestingPersonUpdate(data: {id: "%(person_id)s", name: {value: "Kara Thrace"}}) {
Expand All @@ -228,7 +230,8 @@ async def test_step_04_update_non_profile_attribute(
"person_id": person_1.id,
}

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=mutation,
Expand Down Expand Up @@ -301,9 +304,9 @@ async def test_step_06_get_person_multiple_profiles(self, person_1, person_profi
async def test_step_07_update_person_delete_profile(
self,
db: InfrahubDatabase,
default_branch,
default_branch: Branch,
client,
):
) -> None:
person_2 = await client.get(kind="TestingPerson", name__value="Apollo", property=True)
mutation = """
mutation {
Expand All @@ -329,7 +332,8 @@ async def test_step_07_update_person_delete_profile(
}
""" % {"person_id": person_2.id}

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=mutation,
Expand Down Expand Up @@ -396,10 +400,10 @@ async def test_step_09_check_persons(
async def test_step_10_update_person_override_profile(
self,
db: InfrahubDatabase,
default_branch,
default_branch: Branch,
person_1,
person_profile_1,
):
) -> None:
mutation = """
mutation {
TestingPersonUpdate(data: {id: "%(person_id)s", height: {value: 145}}) {
Expand All @@ -424,7 +428,8 @@ async def test_step_10_update_person_override_profile(
}
""" % {"person_id": person_1.id}

gql_params = await prepare_graphql_params(db=db, include_subscription=False, branch=default_branch)
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
result = await graphql(
schema=gql_params.schema,
source=mutation,
Expand Down
Loading