-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: All the bug fixes listed #170
Changes from 6 commits
24614c4
ed15855
c12f413
26edc76
5efb93d
3228379
f5dc2eb
d419249
6029b23
b82d962
25b8c66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from apps.business_central.exports.journal_entry.tasks import ExportJournalEntry | ||
from apps.business_central.exports.purchase_invoice.tasks import ExportPurchaseInvoice | ||
from apps.fyle.queue import queue_import_credit_card_expenses, queue_import_reimbursable_expenses | ||
from apps.workspaces.models import AdvancedSetting, ExportSetting, FyleCredential | ||
from apps.workspaces.models import AdvancedSetting, BusinessCentralCredentials, ExportSetting, FyleCredential | ||
|
||
from fyle_integrations_platform_connector import PlatformConnector | ||
|
||
|
@@ -31,6 +31,15 @@ def run_import_export(workspace_id: int, export_mode = None): | |
:param workspace_id: Workspace id | ||
""" | ||
|
||
if export_mode == 'AUTOMATIC': | ||
business_central_creds = BusinessCentralCredentials.objects.filter( | ||
workspace_id=workspace_id, is_expired=False, refresh_token__isnull=False | ||
).first() | ||
|
||
if not business_central_creds: | ||
logger.info('Credentials have expired for workspace_id %s', workspace_id) | ||
return | ||
|
||
export_settings = ExportSetting.objects.get(workspace_id=workspace_id) | ||
advance_settings = AdvancedSetting.objects.get(workspace_id=workspace_id) | ||
Comment on lines
42
to
43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Error handling for missing settings is not implemented The 🔗 Analysis chainVerify error handling for missing settings The code directly retrieves 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check for error handling patterns in the codebase
rg -A 2 "ExportSetting.objects.get|AdvancedSetting.objects.get" --type py
Length of output: 9159 Script: #!/bin/bash
# Check for proper DoesNotExist exception handling around ExportSetting.objects.get and AdvancedSetting.objects.get
rg -A 4 "try:" --type py | rg "(ExportSetting\.objects\.get|AdvancedSetting\.objects\.get)\(workspace_id=workspace_id\)" -B 1 | rg "except .*DoesNotExist"
Length of output: 154 Script: #!/bin/bash
# Use ast-grep to find ExportSetting.objects.get and AdvancedSetting.objects.get within try-except blocks handling DoesNotExist
ast-grep --pattern "
try:
$$$
(ExportSetting.objects.get($_) | AdvancedSetting.objects.get($_))
$$$
except DoesNotExist:
$$$
"
Length of output: 172 |
||
accounting_summary, _ = AccountingExportSummary.objects.update_or_create( | ||
|
@@ -58,7 +67,7 @@ def run_import_export(workspace_id: int, export_mode = None): | |
|
||
if accounting_export.status == 'COMPLETE': | ||
accounting_export_ids = AccountingExport.objects.filter( | ||
fund_source='PERSONAL', exported_at__isnull=True).values_list('id', flat=True) | ||
fund_source='PERSONAL', exported_at__isnull=True, workspace_id=workspace_id).values_list('id', flat=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical security fix: Proper workspace isolation added Adding the workspace filter is essential for maintaining proper data isolation between different workspaces. This fix prevents potential data leakage across workspaces. |
||
|
||
if len(accounting_export_ids): | ||
is_expenses_exported = True | ||
|
@@ -75,7 +84,7 @@ def run_import_export(workspace_id: int, export_mode = None): | |
) | ||
if accounting_export.status == 'COMPLETE': | ||
accounting_export_ids = AccountingExport.objects.filter( | ||
fund_source='CCC', exported_at__isnull=True).values_list('id', flat=True) | ||
fund_source='CCC', exported_at__isnull=True, workspace_id=workspace_id).values_list('id', flat=True) | ||
|
||
if len(accounting_export_ids): | ||
is_expenses_exported = True | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
async_create_admin_subcriptions | ||
) | ||
from apps.accounting_exports.models import AccountingExport, AccountingExportSummary | ||
from apps.workspaces.models import FyleCredential, AdvancedSetting, ExportSetting | ||
from apps.workspaces.models import BusinessCentralCredentials, FyleCredential, AdvancedSetting, ExportSetting | ||
from django_q.models import Schedule | ||
from django.conf import settings | ||
from django.urls import reverse | ||
|
@@ -64,6 +64,10 @@ def test_run_import_export_with_reimbursable_expense( | |
'trigger_export' | ||
) | ||
|
||
BusinessCentralCredentials.objects.create( | ||
workspace_id=workspace_id, is_expired=False, refresh_token='bsajkdbasjb' | ||
) | ||
Comment on lines
+67
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add test coverage for missing/expired credentials. While adding the credential creation is good, we should also verify the behavior when:
This ensures we have complete test coverage for the new credential validation in Example test cases to add: def test_run_import_export_without_credentials(
db,
mocker,
create_temp_workspace,
add_fyle_credentials,
create_export_settings,
add_advanced_settings,
create_accounting_export_expenses
):
workspace_id = 1
# Don't create credentials
run_import_export(workspace_id=workspace_id)
# Assert expected behavior
def test_run_import_export_with_expired_credentials(
db,
mocker,
create_temp_workspace,
add_fyle_credentials,
create_export_settings,
add_advanced_settings,
create_accounting_export_expenses
):
workspace_id = 1
BusinessCentralCredentials.objects.create(
workspace_id=workspace_id,
is_expired=True,
refresh_token='expired_token'
)
run_import_export(workspace_id=workspace_id)
# Assert expected behavior |
||
|
||
run_import_export(workspace_id=workspace_id) | ||
|
||
accounting_summary = AccountingExportSummary.objects.get(workspace_id=workspace_id) | ||
|
@@ -114,6 +118,10 @@ def test_run_import_export_with_credit_card_expenses( | |
'trigger_export' | ||
) | ||
|
||
BusinessCentralCredentials.objects.create( | ||
workspace_id=workspace_id, is_expired=False, refresh_token='bsajkdbasjb' | ||
) | ||
|
||
run_import_export(workspace_id=workspace_id, export_mode='AUTOMATIC') | ||
|
||
accounting_summary = AccountingExportSummary.objects.get(workspace_id=workspace_id) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add null check for last_exported_at.
The code assumes
last_exported_at
is always set. If it's null, this could cause unexpected behavior.Consider adding a null check:
Don't forget to add the import:
Review the export counting logic for potential discrepancies.
The new time-based filter is only applied to successful exports but not to failed ones. This inconsistency could lead to:
last_exported_at
Consider applying consistent filtering: