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
1 change: 1 addition & 0 deletions changelog/10.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefix and address attribute filters are now available in the Python SDK
1 change: 1 addition & 0 deletions changelog/30.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Queries using isnull as a filter are now supported by the Python SDK
1 change: 1 addition & 0 deletions changelog/9.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Query filters are not validated locally anymore, the validation will be done on the server side instead.
2 changes: 0 additions & 2 deletions infrahub_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from infrahub_sdk.exceptions import (
AuthenticationError,
Error,
FilterNotFoundError,
GraphQLError,
NodeNotFoundError,
ServerNotReachableError,
Expand Down Expand Up @@ -50,7 +49,6 @@
"InfrahubNodeSync",
"InfrahubRepositoryConfig",
"InfrahubSchema",
"FilterNotFoundError",
"generate_uuid",
"GenericSchema",
"GraphQLQueryAnalyzer",
Expand Down
6 changes: 0 additions & 6 deletions infrahub_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,6 @@ async def filters(
node = InfrahubNode(client=self, schema=schema, branch=branch)
filters = kwargs

if filters:
node.validate_filters(filters=filters)

nodes: list[InfrahubNode] = []
related_nodes: list[InfrahubNode] = []

Expand Down Expand Up @@ -1680,9 +1677,6 @@ def filters(
node = InfrahubNodeSync(client=self, schema=schema, branch=branch)
filters = kwargs

if filters:
node.validate_filters(filters=filters)

nodes: list[InfrahubNodeSync] = []
related_nodes: list[InfrahubNodeSync] = []

Expand Down
3 changes: 1 addition & 2 deletions infrahub_sdk/ctl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from infrahub_sdk.exceptions import (
AuthenticationError,
Error,
FilterNotFoundError,
GraphQLError,
NodeNotFoundError,
SchemaNotFoundError,
Expand Down Expand Up @@ -57,7 +56,7 @@ def handle_exception(exc: Exception, console: Console, exit_code: int):
if isinstance(exc, GraphQLError):
print_graphql_errors(console=console, errors=exc.errors)
raise typer.Exit(code=exit_code)
if isinstance(exc, (SchemaNotFoundError, NodeNotFoundError, FilterNotFoundError)):
if isinstance(exc, (SchemaNotFoundError, NodeNotFoundError)):
console.print(f"[red]Error: {str(exc)}")
raise typer.Exit(code=exit_code)

Expand Down
9 changes: 0 additions & 9 deletions infrahub_sdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,6 @@ def __str__(self) -> str:
"""


class FilterNotFoundError(Error):
def __init__(self, identifier: str, kind: str, message: Optional[str] = None, filters: Optional[list[str]] = None):
self.identifier = identifier
self.kind = kind
self.filters = filters or []
self.message = message or f"{identifier!r} is not a valid filter for {self.kind!r} ({', '.join(self.filters)})."
super().__init__(self.message)


class InfrahubCheckNotFoundError(Error):
def __init__(self, name: str, message: Optional[str] = None):
self.message = message or f"The requested InfrahubCheck '{name}' was not found."
Expand Down
21 changes: 0 additions & 21 deletions infrahub_sdk/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from infrahub_sdk.exceptions import (
Error,
FeatureNotSupportedError,
FilterNotFoundError,
NodeNotFoundError,
UninitializedError,
)
Expand Down Expand Up @@ -987,26 +986,6 @@ def generate_query_data_init(

return data

def validate_filters(self, filters: Optional[dict[str, Any]] = None) -> bool:
if not filters:
return True

for filter_name in filters.keys():
found = False
for filter_schema in self._schema.filters:
if filter_name == filter_schema.name:
found = True
break
if not found:
valid_filters = [entry.name for entry in self._schema.filters]
raise FilterNotFoundError(
identifier=filter_name,
kind=self._schema.kind,
filters=valid_filters,
)

return True

def extract(self, params: dict[str, str]) -> dict[str, Any]:
"""Extract some datapoints defined in a flat notation."""
result: dict[str, Any] = {}
Expand Down
2 changes: 0 additions & 2 deletions infrahub_sdk/protocols_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ def is_resource_pool(self) -> bool: ...

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

def validate_filters(self, filters: Optional[dict[str, Any]] = None) -> bool: ...

def extract(self, params: dict[str, str]) -> dict[str, Any]: ...


Expand Down
15 changes: 1 addition & 14 deletions tests/unit/sdk/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pytest_httpx import HTTPXMock

from infrahub_sdk import InfrahubClient, InfrahubClientSync
from infrahub_sdk.exceptions import FilterNotFoundError, NodeNotFoundError
from infrahub_sdk.exceptions import NodeNotFoundError
from infrahub_sdk.node import InfrahubNode, InfrahubNodeSync

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


@pytest.mark.parametrize("client_type", client_types)
async def test_method_get_invalid_filter(httpx_mock: HTTPXMock, clients, mock_schema_query_01, client_type): # pylint: disable=unused-argument
with pytest.raises(FilterNotFoundError) as excinfo:
if client_type == "standard":
await clients.standard.get(kind="CoreRepository", name__name="infrahub-demo-core")
else:
clients.sync.get(kind="CoreRepository", name__name="infrahub-demo-core")
assert isinstance(excinfo.value.message, str)
assert "'name__name' is not a valid filter for 'CoreRepository'" in excinfo.value.message
assert "default_branch__value" in excinfo.value.message
assert "default_branch__value" in excinfo.value.filters


@pytest.mark.parametrize("client_type", client_types)
async def test_method_filters_many(httpx_mock: HTTPXMock, clients, mock_query_repository_page1_1, client_type): # pylint: disable=unused-argument
if client_type == "standard":
Expand Down