Skip to content

Commit

Permalink
Fix: Handling None case for Iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
Shwetabhk committed Feb 3, 2021
1 parent 2fd50b6 commit 51e6832
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions netsuitesdk/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
from typing import List

logger = logging.getLogger(__name__)

# TODO: introduce arg and return types


# TODO: introduce arg and return types
class ApiBase:
def __init__(self, ns_client, type_name):
self.ns_client = ns_client
self.type_name = type_name

def get_all(self):
return list(self.get_all_generator())
all_records = self.get_all_generator()
return list(all_records) if all_records else []

def get_all_generator(self, page_size=20):
"""
Expand All @@ -25,7 +27,8 @@ def get(self, internalId=None, externalId=None) -> OrderedDict:
return self._get(internalId=internalId, externalId=externalId)

def get_ref(self, internalId=None, externalId=None) -> OrderedDict:
return self._serialize(self.ns_client.RecordRef(type=self.type_name.lower(), internalId=internalId, externalId=externalId))
return self._serialize(self.ns_client.RecordRef(type=self.type_name.lower(),
internalId=internalId, externalId=externalId))

def post(self, data) -> OrderedDict:
raise NotImplementedError('post method not implemented')
Expand All @@ -44,7 +47,8 @@ def _serialize_array(self, records) -> List[OrderedDict]:
"""
return zeep.helpers.serialize_object(records)

def _paginated_search_to_generator(self, paginated_search):
@staticmethod
def _paginated_search_to_generator(paginated_search):
if paginated_search.num_records == 0:
return

Expand All @@ -53,8 +57,6 @@ def _paginated_search_to_generator(self, paginated_search):
logger.debug(f'current page index {paginated_search.page_index}')
logger.debug('going to page %d', 0)

num_records = paginated_search.num_records

records = []

for p in range(1, num_pages + 1):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='netsuitesdk',
version='1.13.0',
version='1.13.1',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down

0 comments on commit 51e6832

Please sign in to comment.