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

Add repetation count #194

Merged
merged 2 commits into from
Jul 23, 2024
Merged

Add repetation count #194

merged 2 commits into from
Jul 23, 2024

Conversation

ruuushhh
Copy link
Contributor

@ruuushhh ruuushhh commented Jun 14, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a repetition_count field to track error occurrences.
  • Improvements

    • Enhanced error handling to increment the repetition_count automatically.

Copy link

coderabbitai bot commented Jun 14, 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 47 minutes and 17 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 d0e89ef and 55050ce.

Walkthrough

This update introduces a new repetition_count field to the Error model in the accounting_exports app. The field tracks the number of times an error has occurred. Adjustments were made across multiple files to increment this counter whenever relevant errors are handled.

Changes

Files Change Summaries
apps/accounting_exports/migrations/0003_error_repetition_count.py Added a migration to include repetition_count in the Error model.
apps/accounting_exports/models.py Added repetition_count field to Error model and method to increment it.
apps/sage300/exceptions.py Updated error handling to increment repetition_count.
apps/sage300/exports/direct_cost/queues.py Reordered imports, updated error handling to increment repetition_count.
apps/sage300/exports/helpers.py Reordered imports, updated error handling to increment repetition_count.
apps/sage300/exports/purchase_invoice/queues.py Reordered imports, updated error handling to increment repetition_count.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant ErrorModel as Error Model
    participant ErrorHandler as Error Handler

    App->>ErrorHandler: Catch Error
    ErrorHandler->>ErrorModel: Update or Create Error Entry
    ErrorModel-->>ErrorHandler: Error Entry Created or Updated
    ErrorHandler->>ErrorModel: Increment repetition_count
    ErrorModel-->>ErrorHandler: Acknowledgment
    ErrorHandler-->>App: Error Handled with repetition_count incremented
Loading

Poem

In the land of code so bright,
Errors abound, day and night.
But with a counter, we stand tall,
Tracking repeats, we handle them all.
Bugs now quiver, they've met their match,
For every count, we'll swiftly catch. 🐇✨


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

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.
  • 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.

Copy link

Tests Skipped Failures Errors Time
133 0 💤 1 ❌ 0 🔥 10.271s ⏱️

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

Outside diff range and nitpick comments (4)
apps/sage300/exceptions.py (1)

Line range hint 63-63: The local variable error in the exception handling block is unused and can be removed to clean up the code.

- error = traceback.format_exc()
apps/sage300/exports/helpers.py (1)

Line range hint 45-46: Replace the string format method with an f-string for better readability and performance. Also, use is None for None comparison.

- category = lineitem.category if (lineitem.category == lineitem.sub_category or lineitem.sub_category == None) else '{0} / {1}'.format(
-     lineitem.category, lineitem.sub_category)
+ category = lineitem.category if lineitem.category == lineitem.sub_category or lineitem.sub_category is None else f'{lineitem.category} / {lineitem.sub_category}'
apps/sage300/exports/direct_cost/queues.py (1)

Line range hint 66-66: Replace the format method with an f-string for clarity and consistency.

- args='{},{}'.format(workspace_id, last_export),
+ args=f'{workspace_id},{last_export}',
apps/sage300/exports/purchase_invoice/queues.py (1)

Line range hint 78-78: Use f-string for string formatting to enhance readability and performance.

- args='{},{}'.format(workspace_id, last_export),
+ args=f'{workspace_id},{last_export}',
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 072a36c and d0e89ef.

Files selected for processing (6)
  • apps/accounting_exports/migrations/0003_error_repetition_count.py (1 hunks)
  • apps/accounting_exports/models.py (2 hunks)
  • apps/sage300/exceptions.py (2 hunks)
  • apps/sage300/exports/direct_cost/queues.py (3 hunks)
  • apps/sage300/exports/helpers.py (3 hunks)
  • apps/sage300/exports/purchase_invoice/queues.py (3 hunks)
Files skipped from review due to trivial changes (1)
  • apps/accounting_exports/migrations/0003_error_repetition_count.py
Additional context used
Ruff
apps/sage300/exceptions.py

19-19: Use implicit references for positional format fields (UP030)

Remove explicit positional indices


19-19: Use f-string instead of format call (UP032)

Convert to f-string


63-63: Local variable error is assigned to but never used (F841)

Remove assignment to unused variable error

apps/sage300/exports/helpers.py

45-45: Comparison to None should be cond is None (E711)

Replace with cond is None


45-46: Use implicit references for positional format fields (UP030)

Remove explicit positional indices


45-46: Use f-string instead of format call (UP032)

Convert to f-string

apps/sage300/exports/direct_cost/queues.py

66-66: Use f-string instead of format call (UP032)

Convert to f-string

apps/sage300/exports/purchase_invoice/queues.py

78-78: Use f-string instead of format call (UP032)

Convert to f-string

Additional comments not posted (6)
apps/sage300/exceptions.py (2)

5-8: Imports are correctly reorganized and necessary for new functionality.


21-23: The update to handle_sage300_error method correctly creates or updates an Error object and increments the repetition_count. This aligns with the PR's objective to track error repetitions.

apps/sage300/exports/helpers.py (1)

Line range hint 69-81: The __validate_category_mapping function correctly creates or updates an Error object and increments the repetition_count when a category mapping error is detected. This is consistent with the PR's objectives.

apps/sage300/exports/direct_cost/queues.py (1)

Line range hint 123-135: The poll_operation_status method correctly handles error logging and increments the repetition_count for errors. This aligns well with the PR's objectives.

apps/sage300/exports/purchase_invoice/queues.py (1)

Line range hint 137-149: The poll_operation_status method correctly handles error creation and increments the repetition_count for errors related to purchase invoices. This aligns well with the PR's objectives.

apps/accounting_exports/models.py (1)

168-168: The addition of the repetition_count field with default value and help text aligns with the PR objectives and Django best practices.

Comment on lines +173 to +178
def increase_repetition_count_by_one(self):
"""
Increase the repetition count by 1.
"""
self.repetition_count += 1
self.save()
Copy link

Choose a reason for hiding this comment

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

Consider using Django's F() expressions to handle potential race conditions when incrementing the repetition_count.

- self.repetition_count += 1
- self.save()
+ from django.db.models import F
+ self.repetition_count = F('repetition_count') + 1
+ self.save(update_fields=['repetition_count'])

This approach ensures that the increment operation is atomic and thread-safe.

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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def increase_repetition_count_by_one(self):
"""
Increase the repetition count by 1.
"""
self.repetition_count += 1
self.save()
def increase_repetition_count_by_one(self):
"""
Increase the repetition count by 1.
"""
from django.db.models import F
self.repetition_count = F('repetition_count') + 1
self.save(update_fields=['repetition_count'])

@@ -20,7 +18,9 @@ def handle_sage300_error(exception, accounting_export: AccountingExport, export_
sage300_error = exception.response
error_msg = 'Failed to create {0}'.format(export_type)
Copy link

Choose a reason for hiding this comment

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

Consider using f-string for improved readability and performance.

- error_msg = 'Failed to create {0}'.format(export_type)
+ error_msg = f'Failed to create {export_type}'
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
error_msg = 'Failed to create {0}'.format(export_type)
error_msg = f'Failed to create {export_type}'
Tools
Ruff

19-19: Use implicit references for positional format fields (UP030)

Remove explicit positional indices


19-19: Use f-string instead of format call (UP032)

Convert to f-string

@ruuushhh ruuushhh temporarily deployed to CI Environment June 14, 2024 06:39 — with GitHub Actions Inactive
Copy link

Tests Skipped Failures Errors Time
133 0 💤 0 ❌ 0 🔥 10.786s ⏱️

@ruuushhh ruuushhh self-assigned this Jun 14, 2024
@ruuushhh ruuushhh temporarily deployed to CI Environment June 14, 2024 06:41 — with GitHub Actions Inactive
@ruuushhh ruuushhh requested a review from ashwin1111 June 14, 2024 06:41
Copy link

Tests Skipped Failures Errors Time
133 0 💤 0 ❌ 0 🔥 10.113s ⏱️

@ruuushhh ruuushhh merged commit 34c47ea into master Jul 23, 2024
2 checks passed
ruuushhh added a commit that referenced this pull request Jul 23, 2024
* Add repetation count

* Fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants