LorenFrankLab / spyglass

Neuroscience data analysis framework for reproducible research built by Loren Frank Lab at UCSF
https://lorenfranklab.github.io/spyglass/
MIT License
94 stars 43 forks source link

super_delete() does not clean up raw and analysis files #1124

Closed magland closed 2 months ago

magland commented 2 months ago

When I use superdelete() I am finding that the raw/session.nwb file does not get cleaned up.

It's because this code of cautious_delete is not included in the super_delete

https://github.com/LorenFrankLab/spyglass/blob/094e002aa4be29fe40c3847e31a169e98617a7ac/src/spyglass/utils/dj_mixin.py#L507C9-L513

BTW: I am using super_delete because if I don't I get an error about user "datajoint" not being found.

samuelbray32 commented 2 months ago

super_delete is calling datajoint's delete function, so we don't have much control of that. This function shouldn't need to be used by the user though, and should instead use delete which gives the extra funtionality

It sounds like your error is because your config isn't set up causing you to fail _check_delete_permission(). You can check your config value for the user with

import datajoint as dj
dj_user = dj.config["database.user"]

Steps for making your config are in the tutorial notebook

magland commented 2 months ago

@samuelbray32 My dj_user from the config is 'datajoint'

Here's the error I am getting when I try to use regular delete

[14:19:35][INFO] Spyglass: Path Found : ['`common_session`.`_session`', '`common_nwbfile`.`nwbfile`']
[14:19:35][INFO] Spyglass: No restr for Session
[14:19:36][ERROR] Spyglass: Uncaught exception
Traceback (most recent call last):
  File "/mnt/home/magland/src/spyglass/jfm/test_import_session.py", line 7, in <module>
    delete_session(session_id)
  File "/mnt/home/magland/src/spyndle/python/spyndle/importing/import_session.py", line 74, in delete_session
    (sgc.Nwbfile & {"nwb_file_name": f"{session_id}_.nwb"}).delete()
  File "/mnt/home/magland/src/spyglass/src/spyglass/utils/dj_mixin.py", line 517, in delete
    self.cautious_delete(*args, **kwargs)
  File "/mnt/home/magland/src/spyglass/src/spyglass/utils/dj_mixin.py", line 496, in cautious_delete
    self._check_delete_permission()
  File "/mnt/home/magland/src/spyglass/src/spyglass/utils/dj_mixin.py", line 416, in _check_delete_permission
    user_name = LabMember().get_djuser_name(dj_user)
  File "/mnt/home/magland/src/spyglass/src/spyglass/common/common_lab.py", line 136, in get_djuser_name
    raise ValueError(
ValueError: Could not find name for datajoint user datajoint in common.LabMember.LabMemberInfo: []

Am I missing a setup step?

CBroz1 commented 2 months ago

You may need to add the user datajoint to common.LabMember.LabMemberInfo