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

Fixing list asset bed preset and list bed preset #2650

Merged

Conversation

DraKen0009
Copy link
Contributor

@DraKen0009 DraKen0009 commented Dec 12, 2024

Proposed Changes

Fixed : #2619

  • Added filter with deleted=False for list bed preset, to fix listing deleted assetbed beds

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

Only PR's with test cases included and passing lint and test pipelines will be reviewed

@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins

Summary by CodeRabbit

  • Bug Fixes
    • Updated the camera preset retrieval to exclude presets linked to deleted asset beds, ensuring more accurate data display.

@DraKen0009 DraKen0009 requested a review from a team as a code owner December 12, 2024 16:31
Copy link

coderabbitai bot commented Dec 12, 2024

Warning

Rate limit exceeded

@DraKen0009 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 20 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

Reviewing files that changed from the base of the PR and between a3acba3 and e5f5edb.

📒 Files selected for processing (1)
  • care/facility/tests/test_assetbed_api.py (1 hunks)
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve a modification to the CameraPresetViewSet class in the care/facility/api/viewsets/camera_preset.py file. The queryset definition has been updated to filter out CameraPreset objects associated with deleted asset_bed entities. This means that only non-deleted asset_bed entries will be considered in the queryset, while the rest of the class methods remain unchanged.

Changes

File Path Change Summary
care/facility/api/viewsets/camera_preset.py Updated queryset in CameraPresetViewSet to filter out CameraPreset instances linked to deleted asset_bed entries.
care/facility/tests/test_assetbed_api.py Added method test_list_bed_with_deleted_assetbed to verify camera presets behavior after asset bed deletion; minor formatting adjustments included.

Poem

In the land of presets, a filter was cast,
To keep only the good, and leave out the past.
No more deleted beds in the view,
Just clean, clear data, for me and for you!
With a simple tweak, the code shines anew,
A small change, but oh, what it can do! 🌟


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

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: 1

🧹 Outside diff range and nitpick comments (1)
care/facility/api/viewsets/camera_preset.py (1)

41-43: Have you considered a more... elegant solution?

While filtering deleted assets works here, it might be worth considering a more centralized approach. Perhaps we could:

  1. Move this logic to a custom model manager
  2. Create a utility function in care.utils.queryset.asset_bed

This would help maintain consistency across the entire codebase, but you know, no pressure or anything.

Example implementation:

# in models.py or managers.py
class CameraPresetManager(models.Manager):
    def active(self):
        return self.filter(asset_bed__deleted=False)

# in viewset
queryset = CameraPreset.objects.active().select_related(...)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88de800 and 3474e84.

📒 Files selected for processing (1)
  • care/facility/api/viewsets/camera_preset.py (1 hunks)
🔇 Additional comments (1)
care/facility/api/viewsets/camera_preset.py (1)

41-43: The filter looks fine, I suppose... but let's verify the implementation.

The addition of asset_bed__deleted=False filter is a reasonable approach to exclude deleted asset beds. However, it would be lovely if we could verify this is the only place that needs this filter.

✅ Verification successful

Well, someone did their homework with the deleted filter...

The asset_bed__deleted=False filter in CameraPresetViewSet is perfectly fine and consistent with the codebase's patterns. I couldn't help but notice that:

  • AssetBedCameraPresetViewSet doesn't need this filter as it uses get_asset_bed_queryset() which presumably handles deletion logic
  • Other viewsets dealing with related entities (like PatientAssetBedViewSet) handle deletion through their own mechanisms
  • The codebase consistently filters deleted records across various viewsets

So, while I suppose we could nitpick about test coverage, the implementation itself is... actually quite proper.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other querysets that might need similar filtering
ast-grep --pattern 'CameraPreset.objects.$_($$$)'

# Look for any other asset_bed related querysets
rg -A 3 'asset_bed.*objects\.' 

Length of output: 1586


Script:

#!/bin/bash
# Let's check if AssetBedCameraPresetViewSet has any filtering
ast-grep --pattern 'class AssetBedCameraPresetViewSet($$$)'

# Check if there are any other places using asset_bed with deleted field
rg -A 3 'asset_bed.*deleted'

# Let's also check the model definition to understand the relationship
ast-grep --pattern 'class CameraPreset($$$)'

Length of output: 487


Script:

#!/bin/bash
# Let's see what AssetBedCameraPresetViewSet actually does
rg -A 10 'class AssetBedCameraPresetViewSet'

# And check if there are any other viewsets dealing with asset_bed
rg -A 5 'class.*AssetBed.*ViewSet'

# One last check for any other deleted filters in viewsets
rg -A 3 'objects\.filter.*deleted'

Length of output: 11889

care/facility/api/viewsets/camera_preset.py Show resolved Hide resolved
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)
care/facility/tests/test_assetbed_api.py (3)

430-430: Remove or complete the commented code.

This line appears to be an incomplete comment. If it was meant to set up test data, it should be removed or completed.

-        # self.asset_bed1.update(deleted=)

431-432: Inconsistent spacing around operators and after commas.

The code would look slightly more polished with consistent spacing around operators and after commas. I mean, if you care about that sort of thing...

-        res=self.client.post(
+        res = self.client.post(

Also applies to: 444-445, 458-460, 465-467


429-469: Test could be more comprehensive.

While the test covers the basic functionality, it might be worth adding a few more assertions to make it absolutely bulletproof:

  1. Verify the remaining preset belongs to asset_bed2
  2. Verify the deleted preset is actually not accessible
  3. Add assertions for the response status codes

Here's a suggested enhancement:

         res = self.client.get(
             f"/api/v1/bed/{self.bed.external_id}/camera_presets/"
         )
+        self.assertEqual(res.status_code, status.HTTP_200_OK)
         self.assertEqual(len(res.json()["results"]), 2)
 
         self.asset_bed1.delete()
         self.asset_bed1.refresh_from_db()
         res = self.client.get(
             f"/api/v1/bed/{self.bed.external_id}/camera_presets/"
         )
+        self.assertEqual(res.status_code, status.HTTP_200_OK)
         self.assertEqual(len(res.json()["results"]), 1)
+        # Verify the remaining preset belongs to asset_bed2
+        self.assertEqual(res.json()["results"][0]["asset_bed"], str(self.asset_bed2.external_id))
+
+        # Verify deleted preset is not accessible
+        res = self.client.get(
+            self.get_base_url(self.asset_bed1.external_id)
+        )
+        self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3474e84 and a3acba3.

📒 Files selected for processing (1)
  • care/facility/tests/test_assetbed_api.py (1 hunks)
🔇 Additional comments (1)
care/facility/tests/test_assetbed_api.py (1)

429-429: Consider adding edge cases for deleted asset beds.

The current test covers the basic scenario, but you might want to consider adding these slightly important edge cases:

  1. Attempting to create a preset for a deleted asset bed
  2. Attempting to update a preset after its asset bed is deleted
  3. Bulk deletion of asset beds and its effect on presets

Let's check if there are any existing tests covering these scenarios:

@vigneshhari vigneshhari merged commit e6d4a48 into ohcnetwork:develop Dec 13, 2024
1 check passed
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.

listAssetBedPresets and ListBedPresets mismatch
2 participants