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

Dandiset "modified" timestamp not updated when entries deleted from Zarr #1871

Open
jwodder opened this issue Feb 26, 2024 · 0 comments
Open
Labels
bug Something isn't working zarr Issues with Zarr hosting/processing/etc.

Comments

@jwodder
Copy link
Member

jwodder commented Feb 26, 2024

When one or more entries are deleted from a Zarr via the DELETE /zarr/{zarr_id}/files/ endpoint — even if the Zarr is then reingested by calling POST /zarr/{zarr_id}/finalize/ — the "modified" properties of both the containing Dandiset and Dandiset version are not updated.

MVCE:

import os
from pathlib import Path
from tempfile import TemporaryDirectory
from time import sleep
from dandi.consts import dandiset_metadata_file
from dandi.dandiapi import DandiAPIClient
from dandi.files import dandi_file
import numpy as np
import zarr

with DandiAPIClient.for_dandi_instance(
    "dandi-staging", token=os.environ["DANDI_API_KEY"]
) as client:

    d = client.create_dandiset(
        "Test Zarr Dandiset",
        {
            "schemaKey": "Dandiset",
            "name": "Test Dandiset",
            "description": "A test Dandiset",
            "contributor": [
                {
                    "schemaKey": "Person",
                    "name": "Wodder, John",
                    "roleName": ["dcite:Author", "dcite:ContactPerson"],
                }
            ],
            "license": ["spdx:CC0-1.0"],
        },
    )

    dandiset_id = d.identifier
    print("DANDISET ID:", dandiset_id)
    try:
        with TemporaryDirectory() as tmpdir:
            dspath = Path(tmpdir)
            (dspath / dandiset_metadata_file).write_text(
                f"identifier: '{dandiset_id}'\n"
            )
            zarr.save(dspath / "sample.zarr", np.arange(1000), np.arange(1000, 0, -1))
            df = dandi_file(dspath / "sample.zarr", dandiset_path=dspath)
            print("Uploading Zarr ...")
            df.upload(d, {"path": "sample.zarr", "description": "A Zarr"})

            d.refresh()
            print("Dandiset modified at:", d.modified)
            print("Dandiset draft version modified at:", d.version.modified)

            print("Sleeping ...")
            sleep(3)

            (asset,) = d.get_assets()
            entry = next(asset.iterfiles())
            print("Deleting entry", entry, "from Zarr")
            asset.rmfiles([entry])

            d.refresh()
            print("Dandiset modified at:", d.modified)
            print("Dandiset draft version modified at:", d.version.modified)
    finally:
        print("Deleting Dandiset ...")
        d.delete()

Sample output:

DANDISET ID: 212987
Uploading Zarr ...
Dandiset modified at: 2024-02-26 14:06:12.328706+00:00
Dandiset draft version modified at: 2024-02-26 14:06:12.527791+00:00
Sleeping ...
Deleting entry .zgroup from Zarr
Dandiset modified at: 2024-02-26 14:06:12.328706+00:00
Dandiset draft version modified at: 2024-02-26 14:06:12.527791+00:00
Deleting Dandiset ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working zarr Issues with Zarr hosting/processing/etc.
Projects
None yet
Development

No branches or pull requests

1 participant