Skip to content

Commit 37e382a

Browse files
authored
Merge pull request #41 from opsmill/dga-20240921-remove-filters
Remove local validation of query filters when calling client.filters()
2 parents 7eb07fb + ca53b9a commit 37e382a

File tree

10 files changed

+5
-56
lines changed

10 files changed

+5
-56
lines changed

changelog/10.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prefix and address attribute filters are now available in the Python SDK

changelog/30.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Queries using isnull as a filter are now supported by the Python SDK

changelog/9.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Query filters are not validated locally anymore, the validation will be done on the server side instead.

infrahub_sdk/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from infrahub_sdk.exceptions import (
1111
AuthenticationError,
1212
Error,
13-
FilterNotFoundError,
1413
GraphQLError,
1514
NodeNotFoundError,
1615
ServerNotReachableError,
@@ -50,7 +49,6 @@
5049
"InfrahubNodeSync",
5150
"InfrahubRepositoryConfig",
5251
"InfrahubSchema",
53-
"FilterNotFoundError",
5452
"generate_uuid",
5553
"GenericSchema",
5654
"GraphQLQueryAnalyzer",

infrahub_sdk/client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,6 @@ async def filters(
623623
node = InfrahubNode(client=self, schema=schema, branch=branch)
624624
filters = kwargs
625625

626-
if filters:
627-
node.validate_filters(filters=filters)
628-
629626
nodes: list[InfrahubNode] = []
630627
related_nodes: list[InfrahubNode] = []
631628

@@ -1680,9 +1677,6 @@ def filters(
16801677
node = InfrahubNodeSync(client=self, schema=schema, branch=branch)
16811678
filters = kwargs
16821679

1683-
if filters:
1684-
node.validate_filters(filters=filters)
1685-
16861680
nodes: list[InfrahubNodeSync] = []
16871681
related_nodes: list[InfrahubNodeSync] = []
16881682

infrahub_sdk/ctl/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from infrahub_sdk.exceptions import (
1919
AuthenticationError,
2020
Error,
21-
FilterNotFoundError,
2221
GraphQLError,
2322
NodeNotFoundError,
2423
SchemaNotFoundError,
@@ -57,7 +56,7 @@ def handle_exception(exc: Exception, console: Console, exit_code: int):
5756
if isinstance(exc, GraphQLError):
5857
print_graphql_errors(console=console, errors=exc.errors)
5958
raise typer.Exit(code=exit_code)
60-
if isinstance(exc, (SchemaNotFoundError, NodeNotFoundError, FilterNotFoundError)):
59+
if isinstance(exc, (SchemaNotFoundError, NodeNotFoundError)):
6160
console.print(f"[red]Error: {str(exc)}")
6261
raise typer.Exit(code=exit_code)
6362

infrahub_sdk/exceptions.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,6 @@ def __str__(self) -> str:
8787
"""
8888

8989

90-
class FilterNotFoundError(Error):
91-
def __init__(self, identifier: str, kind: str, message: Optional[str] = None, filters: Optional[list[str]] = None):
92-
self.identifier = identifier
93-
self.kind = kind
94-
self.filters = filters or []
95-
self.message = message or f"{identifier!r} is not a valid filter for {self.kind!r} ({', '.join(self.filters)})."
96-
super().__init__(self.message)
97-
98-
9990
class InfrahubCheckNotFoundError(Error):
10091
def __init__(self, name: str, message: Optional[str] = None):
10192
self.message = message or f"The requested InfrahubCheck '{name}' was not found."

infrahub_sdk/node.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from infrahub_sdk.exceptions import (
1010
Error,
1111
FeatureNotSupportedError,
12-
FilterNotFoundError,
1312
NodeNotFoundError,
1413
UninitializedError,
1514
)
@@ -987,26 +986,6 @@ def generate_query_data_init(
987986

988987
return data
989988

990-
def validate_filters(self, filters: Optional[dict[str, Any]] = None) -> bool:
991-
if not filters:
992-
return True
993-
994-
for filter_name in filters.keys():
995-
found = False
996-
for filter_schema in self._schema.filters:
997-
if filter_name == filter_schema.name:
998-
found = True
999-
break
1000-
if not found:
1001-
valid_filters = [entry.name for entry in self._schema.filters]
1002-
raise FilterNotFoundError(
1003-
identifier=filter_name,
1004-
kind=self._schema.kind,
1005-
filters=valid_filters,
1006-
)
1007-
1008-
return True
1009-
1010989
def extract(self, params: dict[str, str]) -> dict[str, Any]:
1011990
"""Extract some datapoints defined in a flat notation."""
1012991
result: dict[str, Any] = {}

infrahub_sdk/protocols_base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ def is_resource_pool(self) -> bool: ...
149149

150150
def get_raw_graphql_data(self) -> Optional[dict]: ...
151151

152-
def validate_filters(self, filters: Optional[dict[str, Any]] = None) -> bool: ...
153-
154152
def extract(self, params: dict[str, str]) -> dict[str, Any]: ...
155153

156154

tests/unit/sdk/test_client.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pytest_httpx import HTTPXMock
55

66
from infrahub_sdk import InfrahubClient, InfrahubClientSync
7-
from infrahub_sdk.exceptions import FilterNotFoundError, NodeNotFoundError
7+
from infrahub_sdk.exceptions import NodeNotFoundError
88
from infrahub_sdk.node import InfrahubNode, InfrahubNodeSync
99

1010
async_client_methods = [method for method in dir(InfrahubClient) if not method.startswith("_")]
@@ -329,19 +329,6 @@ async def test_method_get_found_many(
329329
clients.sync.get(kind="CoreRepository", id="bfae43e8-5ebb-456c-a946-bf64e930710a")
330330

331331

332-
@pytest.mark.parametrize("client_type", client_types)
333-
async def test_method_get_invalid_filter(httpx_mock: HTTPXMock, clients, mock_schema_query_01, client_type): # pylint: disable=unused-argument
334-
with pytest.raises(FilterNotFoundError) as excinfo:
335-
if client_type == "standard":
336-
await clients.standard.get(kind="CoreRepository", name__name="infrahub-demo-core")
337-
else:
338-
clients.sync.get(kind="CoreRepository", name__name="infrahub-demo-core")
339-
assert isinstance(excinfo.value.message, str)
340-
assert "'name__name' is not a valid filter for 'CoreRepository'" in excinfo.value.message
341-
assert "default_branch__value" in excinfo.value.message
342-
assert "default_branch__value" in excinfo.value.filters
343-
344-
345332
@pytest.mark.parametrize("client_type", client_types)
346333
async def test_method_filters_many(httpx_mock: HTTPXMock, clients, mock_query_repository_page1_1, client_type): # pylint: disable=unused-argument
347334
if client_type == "standard":

0 commit comments

Comments
 (0)