Skip to content

Commit

Permalink
Fix fields not alllowed exception (#85)
Browse files Browse the repository at this point in the history
* Fix fields not alllowed exception

* Comment resolved

* safely checking exception
  • Loading branch information
Ashutosh619-sudo authored Aug 7, 2024
1 parent ccf6dde commit 3df5d78
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions sageintacctsdk/apis/allocation_entry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import re

from sageintacctsdk.exceptions import WrongParamsError
from .api_base import ApiBase

class AllocationEntry(ApiBase):
Expand All @@ -19,8 +22,28 @@ def get_all_generator(self, field: str = None, value: str = None, fields: list =
fields = self.get_lookup()
if fields and 'Type' in fields and fields['Type'] and 'Relationships' in fields['Type'] and fields['Type']['Relationships'] and 'Relationship' in fields['Type']['Relationships']:
user_defined_dimensions = fields['Type']['Relationships']['Relationship']

for allocation_field in user_defined_dimensions:
allocation_entries_fields.append(allocation_field['RELATEDBY'])

yield from super().get_all_generator(fields=allocation_entries_fields, field=field, value=value)
try:
yield from super().get_all_generator(fields=allocation_entries_fields, field=field, value=value)
except WrongParamsError as e:
error_response = e.response
if error_response is None:
raise
description2 = ''
if 'error' in error_response and isinstance(error_response['error'], list) and error_response['error']:
error = error_response['error'][0]
if 'description2' in error:
description2 = error['description2']

if description2:
match = re.search(r'\n\tallocationentry: \[(.*?)\]', description2)
if match:
removable_fields = match.group(1).split(', ')
for remove_field in removable_fields:
allocation_entries_fields.remove(remove_field)
yield from super().get_all_generator(fields=allocation_entries_fields, field=field, value=value)
else:
raise
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='sageintacctsdk',
version='1.22.3',
version='1.22.4',
author='Ashwin T',
author_email='[email protected]',
description='Python SDK for accessing Sage Intacct APIs',
Expand Down

0 comments on commit 3df5d78

Please sign in to comment.