Skip to content

Commit

Permalink
fix wrong operator used in dynamodb expressions
Browse files Browse the repository at this point in the history
use & instead of and
  • Loading branch information
aymanizz committed Sep 6, 2024
1 parent 6994c48 commit 100bfd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions streaming_status/data_sources/device_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _build_scan_params(
return params


def find_device(provider: str | None, organization: str | None, device_name: str):
def find_device(provider: str | None, organization: str | None, device_name: str) -> dict | None:
key = {"serialNumber": device_name}
device_info = dynamodb.Table(config.device_ledger_table_name).get_item(Key=key).get("Item", {})
device_provider: str = device_info.get("jwtGroup") # type: ignore
Expand Down Expand Up @@ -167,7 +167,7 @@ def list_providers(
condition = Attr("org").eq(organization)
if name_like:
name_like_condition = Attr("jwtGroup").begins_with(name_like)
condition = condition and name_like_condition if condition else name_like_condition
condition = condition & name_like_condition if condition else name_like_condition

params: dict = {"IndexName": config.device_ledger_groups_index_name}
if condition:
Expand Down Expand Up @@ -201,7 +201,7 @@ def _list_organizations_for_provider(
condition: ConditionBase = Key("jwtGroup").eq(provider)
if name_like:
name_like_condition = Key("org").begins_with(name_like)
condition = condition and name_like_condition if condition else name_like_condition
condition = condition & name_like_condition

params: dict = {}
if page:
Expand Down
9 changes: 5 additions & 4 deletions streaming_status/data_sources/fleet_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def list_devices(
page: str | None = None,
page_size: int | None = None,
active_only: bool = True,
):
) -> tuple[str | None, list[dict]]:
query = f"attributes.{ThingAttributeNames.REGISTRATION_WAY}:*"

provider_quoted = provider.replace('"', '\\"') if provider else None
Expand Down Expand Up @@ -51,10 +51,11 @@ def list_devices(
logger.debug("search index query: %s", query)
fleet_result = iot_client.search_index(queryString=query, **request_params)

return fleet_result.get("nextToken"), fleet_result.get("things") or []
things: list[dict] = fleet_result.get("things") # type: ignore
return fleet_result.get("nextToken"), things or []


def find_device(provider: str | None, organization: str | None, device_name: str):
def find_device(provider: str | None, organization: str | None, device_name: str) -> dict | None:
if not device_name_regex.fullmatch(device_name):
raise AppError.invalid_argument(f"name must match the regex: {device_name_regex.pattern}")
if (provider is not None and '"' in provider) or (organization is not None and '"' in organization):
Expand All @@ -70,7 +71,7 @@ def find_device(provider: str | None, organization: str | None, device_name: str
if not result["things"]:
return None

return result["things"][0]
return result["things"][0] # type: ignore


def update_device_active_state(device_name: str, active: bool):
Expand Down

0 comments on commit 100bfd5

Please sign in to comment.