-
Notifications
You must be signed in to change notification settings - Fork 583
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
Use set_view() in builtin view operations #4960
base: develop
Are you sure you want to change the base?
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes in this pull request enhance the functionality of the Changes
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
@imanjra note in the attached video that Interestingly, the exactly analogous steps work for Is it an easy fix to tweak the App so that new saved views can be immediately referenced? save_view_issues.mov |
There was a problem hiding this 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.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- fiftyone/operators/builtin.py (5 hunks)
🧰 Additional context used
🪛 Ruff
fiftyone/operators/builtin.py
1696-1699: Use ternary operator
view = ctx.view if curr_view else _parse_view(ctx, view)
instead ofif
-else
-blockReplace
if
-else
-block withview = ctx.view if curr_view else _parse_view(ctx, view)
(SIM108)
🔇 Additional comments (2)
fiftyone/operators/builtin.py (2)
1737-1744
: Ensure current view is updated after renamingThe code correctly updates the current view if its name has changed, ensuring consistency within the application.
1855-1860
: Reset current view after deleting the active saved viewThe implementation properly resets the current view to the dataset's default view when the active saved view is deleted.
if isinstance(view, str): | ||
view = json.loads(view) | ||
|
||
return fo.DatasetView._build(ctx.dataset, view) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for JSON parsing in _parse_view
Currently, the _parse_view
function does not handle exceptions that might occur during JSON parsing. If view
contains invalid JSON, json.loads(view)
will raise a json.JSONDecodeError
, which is not caught. Consider adding error handling to manage this exception and provide a meaningful error message.
Apply this diff to handle JSON parsing errors:
def _parse_view(ctx, view):
if isinstance(view, str):
- view = json.loads(view)
+ try:
+ view = json.loads(view)
+ except json.JSONDecodeError as e:
+ raise ValueError(f"Invalid JSON for view: {e}")
return fo.DatasetView._build(ctx.dataset, view)
📝 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.
if isinstance(view, str): | |
view = json.loads(view) | |
return fo.DatasetView._build(ctx.dataset, view) | |
if isinstance(view, str): | |
try: | |
view = json.loads(view) | |
except json.JSONDecodeError as e: | |
raise ValueError(f"Invalid JSON for view: {e}") | |
return fo.DatasetView._build(ctx.dataset, view) |
if curr_view: | ||
view = ctx.view | ||
else: | ||
view = _parse_view(ctx, view) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Simplify conditional assignment using a ternary operator
Consider simplifying the assignment of view
by using a ternary operator for conciseness.
Apply this diff to streamline the code:
if curr_view:
view = ctx.view
else:
view = _parse_view(ctx, view)
+view = ctx.view if curr_view else _parse_view(ctx, view)
-
Committable suggestion was skipped due to low confidence.
🧰 Tools
🪛 Ruff
1696-1699: Use ternary operator
view = ctx.view if curr_view else _parse_view(ctx, view)
instead ofif
-else
-blockReplace
if
-else
-block withview = ctx.view if curr_view else _parse_view(ctx, view)
(SIM108)
@brimoor yah, I believe it may require slight refactor. For workspace, I think it does a trip to backend so it can get latest workspaces but for view it does it all in the frontend. I'll check it out. It should be doable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
description=description, | ||
color=color, | ||
overwrite=True, | ||
) | ||
|
||
if curr_view: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of scope of this PR as it matches workspaces, but we should allow opting out of this for programmatic execution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm good point, is there a way to tell if an operator is being executed programmatically vs prompting?
ctx.dataset.update_saved_view_info(name, info) | ||
|
||
if curr_name is not None and curr_name != new_name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
ctx.dataset.delete_saved_view(name) | ||
|
||
if curr_view: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
Just to clarify, we can't merge this until/unless saved views are updated per this comment. As it currently stands, one gets the error notifications pictured in the video there. |
36a1959
to
a28b518
Compare
Updates the builtin
save_view
,edit_saved_view_info
, anddelete_saved_view
operators as follows:save_view
: when saving the current view, usectx.ops.set_view()
to update the App to reflect the fact that the current view is now savededit_saved_view_info
: when renaming the current view, usectx.ops.set_view()
to update the App to reflect the current view's new namedelete_saved_view
: when deleting the current view, reset the App to the full datasetThis is consistent with how
save_workspace
,edit_workspace_info
, anddelete_workspace
work as of #4902.Summary by CodeRabbit
New Features
SaveView
operator.EditSavedViewInfo
operator.LoadWorkspace
andSaveWorkspace
operators for better workspace context handling.Bug Fixes