Skip to content
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: fix export url generation for sandbox accounts #659

Merged

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Nov 6, 2024

Description

The export URLs we generate today look like

https://9370982_sb1.app.netsuite.com/app/accounting/transactions/vendbill.nl?id=109903

This works for regular netsuite accounts, but not for sandbox ones (notice sb in the subdomain name). Netsuite expects a dash - instead of an underscore _

https://9370982-sb1.app.netsuite.com/app/accounting/transactions/vendbill.nl?id=109903

This change fixes the export URL generation, as well as patches the incorrect URLs in the database.

Clickup

https://app.clickup.com/t/86cwzmjkt

Summary by CodeRabbit

  • New Features
    • Enhanced URL generation for NetSuite exports by correctly formatting account IDs containing '_sb'.
    • Introduced a rollback mechanism in the SQL script for updating export URLs in the expense groups table.
  • Bug Fixes
    • Improved error handling during URL generation to ensure robustness.

Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes involve a modification to the generate_netsuite_export_url function in the fyle_netsuite_api/utils.py file. A new line has been added to replace the substring '_sb' with '-sb' in the ns_account_id variable. This adjustment ensures proper formatting of the account ID before constructing the export URL. The function continues to retrieve export type and internal ID from the response_logs dictionary, defaulting to 'chargeCard' when necessary, while maintaining existing error handling. Additionally, a SQL script introduces a rollback mechanism for updating the export_url field in the expense_groups table.

Changes

File Path Change Summary
fyle_netsuite_api/utils.py Modified generate_netsuite_export_url to replace '_sb' with '-sb' in ns_account_id. Function signature updated.
scripts/sql/scripts/029-update-sandbox-export-urls.sql Added a transaction block and rollback mechanism to update export_url in expense_groups, replacing '_sb' with '-sb'.

Poem

In the code where rabbits play,
A change was made, hip-hip-hooray!
With IDs now dressed just right,
Export URLs shine so bright.
Hop along, let errors flee,
For every line, a victory! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the size/XS Extra Small PR label Nov 6, 2024
Copy link

github-actions bot commented Nov 6, 2024

Tests Skipped Failures Errors Time
224 0 💤 0 ❌ 0 🔥 24.727s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
fyle_netsuite_api/utils.py (2)

48-50: Consider adding validation for account ID format.

While the fix works, it would be beneficial to validate the account ID format before processing.

 if '_sb' in ns_account_id:
+    # Validate account ID format (e.g., xxxxxx_sb1 or xxxxxx_sb2)
+    if not re.match(r'^[a-z0-9]+_sb[0-9]?$', ns_account_id):
+        logger.warning(f'Unexpected account ID format: {ns_account_id}')
     ns_account_id = ns_account_id.replace('_sb', '-sb')

48-50: Add a code comment explaining the sandbox URL format requirement.

To improve maintainability, document why this replacement is necessary.

+# NetSuite sandbox accounts require '-sb' format in URLs instead of '_sb'
 if '_sb' in ns_account_id:
     ns_account_id = ns_account_id.replace('_sb', '-sb')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 054b3c1 and 42aaf81.

📒 Files selected for processing (1)
  • fyle_netsuite_api/utils.py (1 hunks)
🔇 Additional comments (1)
fyle_netsuite_api/utils.py (1)

48-50: LGTM! Verify URL format with NetSuite documentation.

The fix correctly handles the NetSuite sandbox account URL format by replacing '_sb' with '-sb'. This change aligns with NetSuite's URL structure.

Let's verify if there are any other instances where this URL format needs to be updated:

✅ Verification successful

URL format change is correctly implemented and isolated

The verification shows that:

  1. The URL format change in utils.py is the only instance handling sandbox account IDs with '_sb'
  2. Other NetSuite URL constructions in the codebase (in apps/netsuite/connector.py) already use the correct '-SB' format
  3. Test fixtures contain properly formatted URLs
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential NetSuite URL constructions or account ID usage
rg -l "netsuite\.com" | xargs rg "_sb"

Length of output: 199


Script:

#!/bin/bash
# Let's check for any other URL construction patterns or account ID handling
rg -A 5 -B 5 "netsuite\.com"

Length of output: 9917

@github-actions github-actions bot added size/S Small PR and removed size/XS Extra Small PR labels Nov 6, 2024
Copy link

github-actions bot commented Nov 6, 2024

Tests Skipped Failures Errors Time
224 0 💤 0 ❌ 0 🔥 25.256s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 42aaf81 and 1e478c5.

📒 Files selected for processing (1)
  • scripts/sql/scripts/029-update-sandbox-export-urls.sql (1 hunks)
🔇 Additional comments (2)
scripts/sql/scripts/029-update-sandbox-export-urls.sql (2)

4-16: LGTM: Well-documented current state.

The comments effectively document the current state and expected changes, which is excellent for validation and future reference.


1-17: Verify the impact of URL changes.

Since this change affects production URLs, we should verify:

  1. That the new URL format is correct and accessible
  2. That there are no unintended side effects in the application
✅ Verification successful

URL format change is aligned with existing code patterns

The URL format change from _sb to -sb is consistent with the existing code in fyle_netsuite_api/utils.py which already handles this conversion for NetSuite account IDs. The codebase scan reveals:

  • The same conversion logic exists in utils.py for account IDs
  • No other hardcoded instances of the old _sb format were found
  • No test files need updating
  • No configuration files contain these patterns

The migration script's change aligns with the application's existing URL handling patterns, making this a safe update.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any hardcoded URL patterns in the codebase that might need updating
rg -g '!*.sql' '_sb' 

# Look for any tests that might need updating
rg -g '*test*.py' '_sb'

Length of output: 205


Script:

#!/bin/bash
# Let's check for both URL patterns to understand the usage
rg -A 3 -B 3 '(_sb|-sb)' .

# Also check for any configuration or environment files that might contain these patterns
fd -e yml -e yaml -e env -e config -e ini -e properties -e json . -x grep -l "_sb\|-sb" {} \;

Length of output: 2070

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername merged commit b353f2f into master Nov 6, 2024
5 checks passed
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Nov 7, 2024
* fix: fix export url generation for sandbox accounts

* fix: add script to update bad db data

(cherry picked from commit b353f2f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy Triggers deployment of active branch to Staging size/S Small PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants