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

Failed delete propagation through PositionGroup #860

Closed
samuelbray32 opened this issue Mar 6, 2024 · 6 comments · Fixed by #899
Closed

Failed delete propagation through PositionGroup #860

samuelbray32 opened this issue Mar 6, 2024 · 6 comments · Fixed by #899
Assignees
Labels
bug Something isn't working merge To do with merge tables

Comments

@samuelbray32
Copy link
Collaborator

samuelbray32 commented Mar 6, 2024

Describe the bug

  • PositionGroup has a part table PositionGroup.Position which is dependent on PositionOutput
  • When a delete in PositionOutput or above tries to pass through this, it fails due to trying to delete from part before master.
  • This is similar to the issue with merge tables, but since PositionOutput isn't a merge table, the solution isn't applied.

Potential Solutions
There may be a simpler way to fix, but one idea would be to have a superclass Group similar to Merge that lets us resolve this type of dependency.

To Reproduce

from spyglass.position.v1 import TrodesPosV1
from spyglass.position import PositionOutput
from spyglass.linearization.merge import LinearizedPositionOutput
from spyglass.decoding.v1.sorted_spikes import PositionGroup
key = "nwb_file_name LIKE 'Bilbo%'"
print(len(TrodesPosV1() & key))
(TrodesPosV1() & key).delete()

Error

{
	"name": "DataJointError",
	"message": "Attempt to delete part table `decoding_core_v1`.`position_group__position` before deleting from its master `decoding_core_v1`.`position_group` first.",
	"stack": "---------------------------------------------------------------------------
DataJointError                            Traceback (most recent call last)
Untitled-1.ipynb Cell 1 line 8
      <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W0sdW50aXRsZWQ%3D?line=5'>6</a> key = \"nwb_file_name LIKE 'Bilbo%'\"
      <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W0sdW50aXRsZWQ%3D?line=6'>7</a> print(len(TrodesPosV1() & key))
----> <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W0sdW50aXRsZWQ%3D?line=7'>8</a> (TrodesPosV1() & key).delete()

File ~/Documents/spyglass/src/spyglass/utils/dj_mixin.py:489, in SpyglassMixin.delete(self, force_permission, *args, **kwargs)
    487 def delete(self, force_permission=False, *args, **kwargs):
    488     \"\"\"Alias for cautious_delete, overwrites datajoint.table.Table.delete\"\"\"
--> 489     self.cautious_delete(force_permission=force_permission, *args, **kwargs)

File ~/Documents/spyglass/src/spyglass/utils/dj_mixin.py:473, in SpyglassMixin.cautious_delete(self, force_permission, *args, **kwargs)
    467     dj_logger.info(f\"Merge: Deleting {count} rows from {table}\")
    468 if (
    469     not self._test_mode
    470     or not safemode
    471     or user_choice(\"Commit deletes?\", default=\"no\") == \"yes\"
    472 ):
--> 473     self._commit_merge_deletes(merge_deletes, **kwargs)
    474 else:
    475     logger.info(\"Delete aborted.\")

File ~/Documents/spyglass/src/spyglass/utils/dj_mixin.py:208, in SpyglassMixin._commit_merge_deletes(self, merge_join_dict, **kwargs)
    206 table = self._merge_tables[table_name]
    207 keys = [part.fetch(MERGE_PK, as_dict=True) for part in part_restr]
--> 208 (table & keys).delete(**kwargs)

File ~/mambaforge-pypy3/envs/spyglass/lib/python3.9/site-packages/datajoint/table.py:601, in Table.delete(self, transaction, safemode, force_parts)
    599             if transaction:
    600                 self.connection.cancel_transaction()
--> 601             raise DataJointError(
    602                 \"Attempt to delete part table {part} before deleting from \"
    603                 \"its master {master} first.\".format(part=part, master=master)
    604             )
    606 # Confirm and commit
    607 if delete_count == 0:

DataJointError: Attempt to delete part table `decoding_core_v1`.`position_group__position` before deleting from its master `decoding_core_v1`.`position_group` first."
}

<\details>

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@samuelbray32 samuelbray32 added bug Something isn't working merge To do with merge tables labels Mar 6, 2024
@samuelbray32
Copy link
Collaborator Author

Not urgent for progress since can get around it by deleting from PositionGroup first and then running the delete command above

@CBroz1
Copy link
Member

CBroz1 commented Mar 29, 2024

This raises a question for me of what delete_downstream_merge should do. I think this case is an example of a false positive in the existing code: it looks like a merge table, but isn't, so the delete doesn't work. In an ideal implementation of my current strategy, this would not have caught this table.

The feature of merge tables that requires this process is part table foreign key inheritance, which this table shares. From here, we could either decide...

  1. Non-merge tables with this feature should throw the 'part-before-master' error.
  2. All Spyglass tables with this feature should delete their master entries, and never hit the above error.

If (2), the solution in #899 should apply to all parts in spyglass, essentially adding a feature to datajoint part tables. The downside would be potentially queuing unexpected items for deletion.

What do you think, @samuelbray32 @edeno ?

@edeno
Copy link
Collaborator

edeno commented Mar 29, 2024

I mean I'm a fan of anything that makes it easier for the users, even it is a departure from datajoint, so I would vote 2. Do you happen to know of any reasons to not do 2? or reasons on the datajoint philosophy for not allowing 2?

@CBroz1
Copy link
Member

CBroz1 commented Mar 29, 2024

No hard reason not to. It is coincidentally explicitly discussed as Option 2 here.

CBroz1 added a commit to CBroz1/spyglass that referenced this issue Mar 29, 2024
@edeno
Copy link
Collaborator

edeno commented Mar 29, 2024

Yeah, I think we should go ahead and do it and not wait for datajoint. Perhaps we can contribute back or make it a more urgent issue for them in the future.

@CBroz1 CBroz1 mentioned this issue Mar 29, 2024
4 tasks
edeno pushed a commit that referenced this issue Apr 19, 2024
* #892

* #885

* #879

* Partial address of #860

* Update Changelog

* Partial solve of #886 - Ask import

* Fix failing tests

* Add note on order of inheritace

* #933

* Could not replicate fill_nan error. Reverting except clause
@CBroz1
Copy link
Member

CBroz1 commented Apr 24, 2024

Awaiting feedback on proposed edit to datajoint here

edeno added a commit that referenced this issue Apr 25, 2024
* Add spyglass version to created analysis nwb files (#897)

* Add sg version to created analysis nwb files

* update changelog

* Change existing source script to spyglass version (#900)

* Add pynapple support (#898)

* Preliminary code

* Add retrieval of file names

* Add get_nwb_table function

* Update docstrings

* Update CHANGELOG.md

* Hot fixes for clusterless `get_ahead_behind_distance` and `get_spike_times` (#904)

* Squeeze results

* Make method and not class method

* Update CHANGELOG.md

* fix bugs in fetch_nwb (#913)

* Check for entry in merge part table prior to insert (#922)

* check for entry in merge part table prior to insert

* update changelog

* Kachery fixes (#918)

* Prioritize datajoint filepath for getting analysis file abs_path

* remove deprecated kachery tables

* update changelog

* fix lint

---------

Co-authored-by: Samuel Bray <[email protected]>
Co-authored-by: Eric Denovellis <[email protected]>

* remove old tables from init (#925)

* Fix improper uses of strip (#929)

Strip will remove leading characters

* Update CHANGELOG.md

* Misc Issues (#903)

* #892

* #885

* #879

* Partial address of #860

* Update Changelog

* Partial solve of #886 - Ask import

* Fix failing tests

* Add note on order of inheritace

* #933

* Could not replicate fill_nan error. Reverting except clause

* Export logger (#875)

* WIP: rebase Export process

* WIP: revise doc

* ✅ : Generate working export script

* Cleanup: Expand notebook, migrate export process from graph class to export

* Revert dj_chains related edits

* Update changelog

* Revise doc

* Address review comments #875

* Remove walrus in  eval

* prevent log on preview

* Fix arg order on fetch, iterate over restr

* Add upstream analysis files during cascade. Address false positive fetch

* Avoid regen file list on revisit node

* Bump Export.Table.restr to mediumblob

* Revise Export.Table uniqueness to include export_id

* Spikesorting quality of life helpers (#910)

* add utitlity function for finding spikesorting merge ids

* add option to select v1 sorts that didn't go through artifact detection

* add option to return merge keys as dicts for future restrictions

* Add tool to get brain region and electrode info for a spikesorting merge id

* update changelog

* style cleanup

* style cleanup

* fix restriction bug for curation_id

* account for change or radiu_um argument name in spikeinterface

* only do joins with metric curastion tables if have relevant keys in the restriction

* Update tutorial to use spikesorting merge table helper functions

* fix spelling

* Add logging of AnalysisNwbfile creation time and file size (#937)

* Add logging for any func that creates AnalysisNwbfile

* Migrate create to top of respective funcs

* Use pathlib for file size. Bump creation time to top of  in spikesort

* Clear pre_create_time on create

* get/del -> pop

* Log when file accessed (#941)

* Add logging for any func that creates AnalysisNwbfile

* Fix bug on empty delete in merge table (#940)

* fix bug on empty delete in merge table

* update changelog

* fix spelling

---------

Co-authored-by: Chris Brozdowski <[email protected]>

* Remove master restriction

* Part delete takes restriction from self

---------

Co-authored-by: Samuel Bray <[email protected]>
Co-authored-by: Eric Denovellis <[email protected]>
Co-authored-by: Samuel Bray <[email protected]>
Co-authored-by: Eric Denovellis <[email protected]>
@edeno edeno closed this as completed in #899 May 6, 2024
edeno added a commit that referenced this issue May 6, 2024
* Create class for group parts to help propagate deletes

* spelling

* update changelog

* Part delete edits (#946)

* Add spyglass version to created analysis nwb files (#897)

* Add sg version to created analysis nwb files

* update changelog

* Change existing source script to spyglass version (#900)

* Add pynapple support (#898)

* Preliminary code

* Add retrieval of file names

* Add get_nwb_table function

* Update docstrings

* Update CHANGELOG.md

* Hot fixes for clusterless `get_ahead_behind_distance` and `get_spike_times` (#904)

* Squeeze results

* Make method and not class method

* Update CHANGELOG.md

* fix bugs in fetch_nwb (#913)

* Check for entry in merge part table prior to insert (#922)

* check for entry in merge part table prior to insert

* update changelog

* Kachery fixes (#918)

* Prioritize datajoint filepath for getting analysis file abs_path

* remove deprecated kachery tables

* update changelog

* fix lint

---------

Co-authored-by: Samuel Bray <[email protected]>
Co-authored-by: Eric Denovellis <[email protected]>

* remove old tables from init (#925)

* Fix improper uses of strip (#929)

Strip will remove leading characters

* Update CHANGELOG.md

* Misc Issues (#903)

* #892

* #885

* #879

* Partial address of #860

* Update Changelog

* Partial solve of #886 - Ask import

* Fix failing tests

* Add note on order of inheritace

* #933

* Could not replicate fill_nan error. Reverting except clause

* Export logger (#875)

* WIP: rebase Export process

* WIP: revise doc

* ✅ : Generate working export script

* Cleanup: Expand notebook, migrate export process from graph class to export

* Revert dj_chains related edits

* Update changelog

* Revise doc

* Address review comments #875

* Remove walrus in  eval

* prevent log on preview

* Fix arg order on fetch, iterate over restr

* Add upstream analysis files during cascade. Address false positive fetch

* Avoid regen file list on revisit node

* Bump Export.Table.restr to mediumblob

* Revise Export.Table uniqueness to include export_id

* Spikesorting quality of life helpers (#910)

* add utitlity function for finding spikesorting merge ids

* add option to select v1 sorts that didn't go through artifact detection

* add option to return merge keys as dicts for future restrictions

* Add tool to get brain region and electrode info for a spikesorting merge id

* update changelog

* style cleanup

* style cleanup

* fix restriction bug for curation_id

* account for change or radiu_um argument name in spikeinterface

* only do joins with metric curastion tables if have relevant keys in the restriction

* Update tutorial to use spikesorting merge table helper functions

* fix spelling

* Add logging of AnalysisNwbfile creation time and file size (#937)

* Add logging for any func that creates AnalysisNwbfile

* Migrate create to top of respective funcs

* Use pathlib for file size. Bump creation time to top of  in spikesort

* Clear pre_create_time on create

* get/del -> pop

* Log when file accessed (#941)

* Add logging for any func that creates AnalysisNwbfile

* Fix bug on empty delete in merge table (#940)

* fix bug on empty delete in merge table

* update changelog

* fix spelling

---------

Co-authored-by: Chris Brozdowski <[email protected]>

* Remove master restriction

* Part delete takes restriction from self

---------

Co-authored-by: Samuel Bray <[email protected]>
Co-authored-by: Eric Denovellis <[email protected]>
Co-authored-by: Samuel Bray <[email protected]>
Co-authored-by: Eric Denovellis <[email protected]>

* Fix linting

---------

Co-authored-by: Chris Brozdowski <[email protected]>
Co-authored-by: Eric Denovellis <[email protected]>
Co-authored-by: Samuel Bray <[email protected]>
Co-authored-by: Eric Denovellis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working merge To do with merge tables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants