Skip to content

Commit 81089af

Browse files
committed
fix config
1 parent e4385fe commit 81089af

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

infrahub_sdk/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@ def _build_ip_prefix_allocation_query(
271271
input_data={"data": input_data},
272272
)
273273

274-
def _clone_config(self, branch: str | None = None) -> Config:
275-
config = copy.deepcopy(self.config)
276-
config.default_branch = branch or config.default_branch
277-
return config
278-
279274

280275
class InfrahubClient(BaseClient):
281276
"""GraphQL Client to interact with Infrahub."""
@@ -854,7 +849,7 @@ async def process_non_batch() -> tuple[list[InfrahubNode], list[InfrahubNode]]:
854849

855850
def clone(self, branch: str | None = None) -> InfrahubClient:
856851
"""Return a cloned version of the client using the same configuration"""
857-
return InfrahubClient(config=self._clone_config(branch=branch))
852+
return InfrahubClient(config=self.config.clone(branch=branch))
858853

859854
async def execute_graphql(
860855
self,
@@ -1598,7 +1593,7 @@ def delete(self, kind: str | type[SchemaTypeSync], id: str, branch: str | None =
15981593

15991594
def clone(self, branch: str | None = None) -> InfrahubClientSync:
16001595
"""Return a cloned version of the client using the same configuration"""
1601-
return InfrahubClientSync(config=self._clone_config(branch=branch))
1596+
return InfrahubClientSync(config=self.config.clone(branch=branch))
16021597

16031598
def execute_graphql(
16041599
self,

infrahub_sdk/config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from copy import deepcopy
34
from typing import Any
45

56
from pydantic import Field, field_validator, model_validator
@@ -158,3 +159,19 @@ def set_custom_recorder(cls, values: dict[str, Any]) -> dict[str, Any]:
158159
elif values.get("recorder") == RecorderType.JSON and "custom_recorder" not in values:
159160
values["custom_recorder"] = JSONRecorder()
160161
return values
162+
163+
def clone(self, branch: str | None = None) -> Config:
164+
config: dict[str, Any] = {
165+
"default_branch": branch or self.default_branch,
166+
"recorder": self.recorder,
167+
"custom_recorder": self.custom_recorder,
168+
"requester": self.requester,
169+
"sync_requester": self.sync_requester,
170+
"log": self.log,
171+
}
172+
covered_keys = list(config.keys())
173+
for field in self.model_fields.keys():
174+
if field not in covered_keys:
175+
config[field] = deepcopy(getattr(self, field))
176+
177+
return Config(**config)

0 commit comments

Comments
 (0)