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 Creds for connection call #93

Merged
merged 3 commits into from
Feb 12, 2024
Merged

Fix Creds for connection call #93

merged 3 commits into from
Feb 12, 2024

Conversation

ruuushhh
Copy link
Contributor

@ruuushhh ruuushhh commented Feb 8, 2024

Summary by CodeRabbit

  • Refactor
    • Improved the method for retrieving BusinessCentralCredentials to enhance reliability and efficiency.

@ruuushhh ruuushhh added the deploy deploy to staging environment label Feb 8, 2024
Copy link

coderabbitai bot commented Feb 8, 2024

Warning

Rate Limit Exceeded

@ruuushhh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 59 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 5581041 and 3af2ff6.

Walkthrough

The change primarily focuses on updating the method of retrieving BusinessCentralCredentials in the get_company function within a specific serializer file. By transitioning from a custom retrieval method to utilizing the objects.get method with added filtering criteria, the update aims to streamline and possibly enhance the efficiency or reliability of the process.

Changes

File Path Change Summary
.../business_central/serializers.py Modified get_company to use objects.get with additional filters for BusinessCentralCredentials retrieval.

🐇✨
In the heart of the code, under digital skies,
A small change blooms, wisdom in disguise.
Through fields of data, swift we hop,
Crafting the future, byte by byte, non-stop.
🌟🐾

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

github-actions bot commented Feb 8, 2024

Tests Skipped Failures Errors Time
48 0 💤 0 ❌ 0 🔥 5.009s ⏱️

Copy link

github-actions bot commented Feb 8, 2024

Tests Skipped Failures Errors Time
48 0 💤 0 ❌ 0 🔥 5.020s ⏱️

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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 59ca2d2 and 5581041.
Files selected for processing (1)
  • apps/business_central/serializers.py (1 hunks)

Comment on lines +135 to +137
business_central_credentials: BusinessCentralCredentials = BusinessCentralCredentials.objects.get(
workspace_id=workspace_id, is_expired=False, refresh_token__isnull=False
)
Copy link

Choose a reason for hiding this comment

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

The change to use objects.get with additional filtering criteria (workspace_id=workspace_id, is_expired=False, refresh_token__isnull=False) for retrieving BusinessCentralCredentials is a significant improvement in terms of security and reliability. This ensures that only valid, non-expired credentials with a refresh token are used for establishing connections. However, consider handling the case where multiple credentials match the criteria, as objects.get will raise a MultipleObjectsReturned exception if more than one item matches the query. This scenario might occur if there are data inconsistencies or errors in how credentials are managed. Adding explicit handling for this exception or ensuring data integrity to prevent such cases is recommended.


The retrieval of BusinessCentralCredentials using objects.get is correctly implemented with the necessary filtering criteria. However, ensure that the system is designed to handle or prevent multiple credentials matching the criteria to avoid MultipleObjectsReturned exceptions.


The exception handling for WrongParamsError and InvalidTokenError assumes that business_central_credentials is always available, which might not be the case if the exception is raised before its assignment. Consider restructuring the code to ensure that the invalidation logic is only executed when business_central_credentials is defined.

        except (WrongParamsError, InvalidTokenError):
-           if business_central_credentials:
+           try:
                business_central_credentials.refresh_token = None
                business_central_credentials.is_expired = True
                business_central_credentials.save()
+           except NameError:
+               pass

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
business_central_credentials: BusinessCentralCredentials = BusinessCentralCredentials.objects.get(
workspace_id=workspace_id, is_expired=False, refresh_token__isnull=False
)

Copy link

github-actions bot commented Feb 8, 2024

Tests Skipped Failures Errors Time
48 0 💤 0 ❌ 0 🔥 5.057s ⏱️

@ruuushhh ruuushhh added deploy deploy to staging environment and removed deploy deploy to staging environment labels Feb 8, 2024
Copy link

github-actions bot commented Feb 8, 2024

Tests Skipped Failures Errors Time
48 0 💤 0 ❌ 0 🔥 4.933s ⏱️

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (59ca2d2) 80.13% compared to head (3af2ff6) 80.13%.

Files Patch % Lines
apps/business_central/serializers.py 0.00% 1 Missing ⚠️
apps/workspaces/helpers.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master      #93   +/-   ##
=======================================
  Coverage   80.13%   80.13%           
=======================================
  Files          67       67           
  Lines        3337     3337           
=======================================
  Hits         2674     2674           
  Misses        663      663           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Feb 8, 2024

Tests Skipped Failures Errors Time
48 0 💤 0 ❌ 0 🔥 5.105s ⏱️

Comment on lines +135 to +137
business_central_credentials: BusinessCentralCredentials = BusinessCentralCredentials.objects.get(
workspace_id=workspace_id, is_expired=False, refresh_token__isnull=False
)
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't these condition same as get_active_business_central_credentials?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I updated it to filter

@ruuushhh ruuushhh merged commit a6642d0 into master Feb 12, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy deploy to staging environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants