Commit 11ffcc52 by Oleksandr Barabash

get_first_or_none updated

parent a12d0910
...@@ -19,6 +19,7 @@ from entities.json.camel_case_mixin import timestamp_factory ...@@ -19,6 +19,7 @@ from entities.json.camel_case_mixin import timestamp_factory
from entities.json.conversation_reference import ConversationReference from entities.json.conversation_reference import ConversationReference
from entities.json.initiation import Initiation from entities.json.initiation import Initiation
from entities.json.notification import NotificationCosmos from entities.json.notification import NotificationCosmos
from utils.functions import get_first_or_none
from utils.log import Log from utils.log import Log
...@@ -123,7 +124,7 @@ class CosmosClient: ...@@ -123,7 +124,7 @@ class CosmosClient:
next_page = pager.next() next_page = pager.next()
Log.d(TAG, f"get_next_page_bl::next_page:{next_page}," Log.d(TAG, f"get_next_page_bl::next_page:{next_page},"
f"list({list(next_page)})") f"list({list(next_page)})")
return list(next_page)[0] return get_first_or_none(list(next_page), list())
except StopIteration: except StopIteration:
Log.e(TAG, "get_next_page_bl:: no items found, returning '[]'", Log.e(TAG, "get_next_page_bl:: no items found, returning '[]'",
exc_info=sys.exc_info()) exc_info=sys.exc_info())
......
...@@ -40,11 +40,11 @@ def get_i18n(turn_context: TurnContext, ...@@ -40,11 +40,11 @@ def get_i18n(turn_context: TurnContext,
return i18n return i18n
def get_first_or_none(items: List) -> Optional[Dict[str, any]]: def get_first_or_none(items: List, default=None) -> Optional[Dict[str, any]]:
""" Get first object from list or return None len < 1 """ """ Get first object from list or return None len < 1 """
if len(items) > 0: if len(items) > 0:
return items[0] return items[0]
return None return default
def parse_auth_header(header: Optional[str]) -> Tuple[Optional[str], def parse_auth_header(header: Optional[str]) -> Tuple[Optional[str],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment