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: Disable items category #674

Merged
merged 10 commits into from
Sep 25, 2024
Merged

fix: Disable items category #674

merged 10 commits into from
Sep 25, 2024

Conversation

Hrishabh17
Copy link
Contributor

@Hrishabh17 Hrishabh17 commented Sep 25, 2024

Description

Fix for Items disable, we would disable all items only via trigger of general settings

Clickup

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

Summary by CodeRabbit

  • New Features

    • Enhanced handling of workspace general settings with new conditions for asynchronous task execution.
  • Bug Fixes

    • Improved logic for managing the state of import items based on changes in workspace settings.
  • Chores

    • Updated subproject reference to the latest version for improved functionality.

Copy link

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes introduce enhancements to the post_save_workspace_general_settings method in the ImportSettingsTrigger class across two files. A new variable, pre_save_general_settings, is added to capture the previous state of workspace settings, allowing for better handling of changes. Additionally, an asynchronous task is triggered if the import_items setting transitions from enabled to disabled. A subproject reference is also updated, indicating a version change.

Changes

File(s) Change Summary
apps/.../serializers.py Introduced pre_save_general_settings variable; updated method signature of post_save_workspace_general_settings to include this new parameter.
apps/.../triggers.py Added import for async_task; modified method signature of post_save_workspace_general_settings to include old_workspace_general_settings and added logic for conditional task execution.
fyle_integrations_imports Updated subproject commit reference from 3a7b84d8edc5f5d131441d67c3e4b08b435f4dac to f0c509e8fcfaa2b09ea40473a60bea2383766ee1.

Possibly related PRs

  • fix categories disable p0 bug #666: This PR modifies the sync_accounts method to include a new parameter based on workspace settings, similar to how the main PR introduces a new variable for workspace general settings in the post_save_workspace_general_settings method.
  • feat: disable items - category #667: This PR alters the handling of import_items in the construct_tasks_and_chain_import_fields_to_fyle function, which relates to the changes in the main PR that also involve conditional checks based on workspace general settings.

Suggested labels

deploy

Suggested reviewers

  • ruuushhh
  • ashwin1111

Poem

In the burrow where changes bloom,
Settings shift, dispelling gloom.
With tasks that hop and swiftly run,
Our workspace shines, a job well done!
A rabbit's cheer for code so bright,
Enhancing flows with pure delight! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7d03d57 and 8acd3b5.

📒 Files selected for processing (1)
  • fyle_integrations_imports (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • fyle_integrations_imports

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 Sep 25, 2024
Copy link

PR title must start with "fix:", "feat:", "chore:", "refactor", or "test:" (case-insensitive)

@Hrishabh17 Hrishabh17 changed the title Disable items category fix: Disable items category Sep 25, 2024
Copy link

Tests Skipped Failures Errors Time
259 0 💤 0 ❌ 0 🔥 49.430s ⏱️

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 (3)
apps/workspaces/apis/import_settings/triggers.py (1)

78-79: LGTM: New trigger for disabling items implemented correctly.

The new conditional block successfully implements the trigger for disabling items when the import_items setting is turned off. The use of async_task is appropriate for handling this potentially time-consuming operation.

Consider adding a brief comment explaining the purpose of this condition for improved code readability:

+    # Trigger item disabling when import_items is turned off
     if not workspace_general_settings_instance.import_items and old_workspace_general_settings.import_items:
         async_task('fyle_integrations_imports.tasks.disable_items', workspace_id=self.__workspace_id, is_import_enabled=False)
apps/workspaces/apis/import_settings/serializers.py (2)

95-96: LGTM! Consider using get() for slight optimization.

The introduction of pre_save_general_settings is a good approach to capture the pre-update state of general settings. This will allow for comparison in the post_save_workspace_general_settings method.

Consider using get() instead of filter().first() for a slight optimization, as we expect only one instance per workspace:

pre_save_general_settings = WorkspaceGeneralSettings.objects.get(workspace_id=instance.id)

If there's a possibility that the instance might not exist, you can use get_or_none() from Django's get_object_or_404 utility:

from django.shortcuts import get_object_or_404

pre_save_general_settings = get_object_or_404(WorkspaceGeneralSettings, workspace_id=instance.id)

This will raise a 404 error if the instance doesn't exist, which might be preferable depending on your error handling strategy.


Line range hint 1-180: Summary: Changes align with PR objective, suggest thorough testing

The changes introduced in this file are minimal but significant. They align well with the PR objective of implementing a fix to disable all items through a trigger in general settings. The introduction of pre_save_general_settings and its usage in the post_save_workspace_general_settings method call allow for comparison between pre and post-update states of general settings.

To ensure the reliability of these changes:

  1. Implement comprehensive unit tests for the update method in ImportSettingsSerializer, focusing on the new functionality.
  2. Add integration tests to verify the interaction between ImportSettingsSerializer and ImportSettingsTrigger.
  3. Perform manual testing to ensure that disabling all items through general settings works as expected in various scenarios.

These steps will help maintain the robustness of the import settings functionality and prevent potential regressions in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 589ca7c and 7d03d57.

📒 Files selected for processing (3)
  • apps/workspaces/apis/import_settings/serializers.py (2 hunks)
  • apps/workspaces/apis/import_settings/triggers.py (2 hunks)
  • fyle_integrations_imports (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • fyle_integrations_imports
🔇 Additional comments not posted (4)
apps/workspaces/apis/import_settings/triggers.py (3)

3-3: LGTM: New import for async task execution.

The addition of async_task from django_q.tasks is appropriate for the new asynchronous task execution implemented in the post_save_workspace_general_settings method.


74-74: LGTM: Updated method signature for comparing old and new settings.

The addition of the old_workspace_general_settings parameter allows for comparison between the previous and current settings, which is necessary for implementing the new trigger functionality for disabling items.


Line range hint 1-138: Summary: Changes successfully implement the item disabling trigger.

The modifications in this file effectively implement the trigger for disabling items through general settings, as outlined in the PR objectives. The new import, updated method signature, and conditional logic work together to achieve the desired functionality. The implementation uses asynchronous task execution, which is appropriate for potentially time-consuming operations.

apps/workspaces/apis/import_settings/serializers.py (1)

113-113: LGTM! Verify ImportSettingsTrigger class implementation.

The modification to pass pre_save_general_settings to post_save_workspace_general_settings aligns with the PR objective. This change allows for comparison between pre and post-update states, which is crucial for implementing the functionality to disable all items through a trigger in general settings.

Please ensure that the ImportSettingsTrigger class has been updated to handle this new argument in its post_save_workspace_general_settings method. Run the following script to verify:

If the script doesn't return any results, it means the ImportSettingsTrigger class needs to be updated to match the new method signature.

✅ Verification successful

Verified!

The ImportSettingsTrigger class correctly implements the post_save_workspace_general_settings method with the additional old_workspace_general_settings parameter. This ensures that the method can effectively compare pre and post-update states, fulfilling the PR's objective to disable all items through a trigger in general settings.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the ImportSettingsTrigger class implementation

# Test: Check if the post_save_workspace_general_settings method in ImportSettingsTrigger accepts two arguments
ast-grep --lang python --pattern $'class ImportSettingsTrigger:
  $$$
  def post_save_workspace_general_settings(self, $_, $_):
    $$$'

Length of output: 13453


Script:

#!/bin/bash
# Description: Verify the ImportSettingsTrigger class implementation with multi-line method signature

# Test: Check if the post_save_workspace_general_settings method in ImportSettingsTrigger accepts two arguments, allowing for multi-line definitions
ast-grep --lang python --pattern $'class ImportSettingsTrigger:
  $$$
  def post_save_workspace_general_settings(
    self,
    $_,
    $_
  ):
    $$$'

Length of output: 13469


Script:

#!/bin/bash
# Description: Verify the ImportSettingsTrigger class implementation with single-line method signature

# Test: Check if the post_save_workspace_general_settings method in ImportSettingsTrigger accepts two arguments on a single line
ast-grep --lang python --pattern $'class ImportSettingsTrigger:
  $$$
  def post_save_workspace_general_settings(self, $_, $_):
    $$$'

Length of output: 13453


Script:

#!/bin/bash
# Description: Verify the ImportSettingsTrigger class implementation with type-annotated method signature

# Test: Check if the post_save_workspace_general_settings method in ImportSettingsTrigger accepts two arguments with type annotations
ast-grep --lang python --pattern $'class ImportSettingsTrigger:
  $$$
  def post_save_workspace_general_settings(self, $_: $_, $_: $_):
    $$$'

Length of output: 13461


Script:

#!/bin/bash
# Description: Verify the ImportSettingsTrigger class implementation using ripgrep to find method signature

# Test: Search for the post_save_workspace_general_settings method and count the number of parameters
rg 'def post_save_workspace_general_settings\s*\(.*self\s*,\s*[^,]+,\s*[^)]+\)' apps/workspaces/apis/import_settings/triggers.py

Length of output: 303

Copy link

Tests Skipped Failures Errors Time
259 0 💤 0 ❌ 0 🔥 59.248s ⏱️

@Hrishabh17 Hrishabh17 merged commit 7d8ef97 into master Sep 25, 2024
4 checks passed
Hrishabh17 added a commit that referenced this pull request Sep 30, 2024
* disable/enable items

* update submodule

* update submodule

* update submodule

* add tests for cov

* fix: disable items with trigger import settings

* update submodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XS Extra Small PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants