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 support for deleting variables #180

Merged
merged 1 commit into from
Jan 30, 2024
Merged

Add support for deleting variables #180

merged 1 commit into from
Jan 30, 2024

Conversation

JamesWrigley
Copy link
Member

This is mildly cursed because it will reload the database upon deletion. For two reasons:

  • There are lingering bugs surrounding moving columns after changing the number of variables, and I don't want to deal with that right now.
  • Laziness 😇

My justification is that deleting a variable is something that will (hopefully) occur rarely, and occur when writing the context file for the first time while the database is likely to be empty-ish (so it won't take an obnoxious amount of time to reload). Plus, loading databases isn't too awful with the v1 format.

Another thing I'm unsure about is the location of the api.delete_variable() function. I put it in api.py because I have vague ideas about having a writable wrapper for a future read-only API (exposed to users through a separate package), but I couldn't think of a nice way to fit that into the VariableData/RunVariables classes. I also considered merging it with DamnitDB.delete_variable() but then DamnitDB would come to mean 'database and HDF5 files' while it's currently just 'database'. Not sure how I feel about that.

Demo:
damnit-delete-variable

Fixes #69.

@@ -44,6 +46,10 @@ def __init__(self) -> None:
self._columns_widget.itemChanged.connect(self.item_changed)
self._columns_widget.model().rowsMoved.connect(self.item_moved)

self._columns_widget.setContextMenuPolicy(Qt.CustomContextMenu)
self._columns_widget.customContextMenuRequested.connect(self.show_delete_menu)
delete_action = QtWidgets.QAction("Delete")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
delete_action = QtWidgets.QAction("Delete")

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops 🙈 Removed in 82a5e55.

@tmichela
Copy link
Member

Looks good enough to me, since we don't plan to maintain this ui.
We could maybe add a comment that reloading the entire database is due to an other bug (or make an issue about it), so we can change that if the bug gets fixed.

@JamesWrigley
Copy link
Member Author

Sure, added a comment in 82a5e55.

@tmichela
Copy link
Member

LGTM

This is mildly cursed because it will reload the database upon deletion. For two
reasons:
- There are lingering bugs surrounding moving columns after changing the number
  of variables, and I don't want to deal with that right now.
- Laziness

My justification is that deleting a variable is something that will (hopefully)
occur rarely, and occur when writing the context file for the first time while
the database is likely to be empty-ish.
@JamesWrigley JamesWrigley merged commit 10a0433 into master Jan 30, 2024
3 checks passed
@JamesWrigley JamesWrigley deleted the delete-variables branch January 30, 2024 09:42
@tmichela
Copy link
Member

I just realized... what would happen if multiple clients are connected to the same database. The other clients don't know the variable is deleted and may try to access the data. Will it crash?

@JamesWrigley
Copy link
Member Author

Oh dear, that is an excellent point 🤦 I'll make another PR to broadcast a deletion message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete variables from the database
2 participants