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

Remove Asset.previous field #2008

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified dandiapi/api/fixtures/playwright.json.xz
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, why does this file need to be changed as a part of this PR? Since I don't believe the API surface is changing at all.

Binary file not shown.
17 changes: 17 additions & 0 deletions dandiapi/api/migrations/0011_remove_asset_previous.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.1.13 on 2024-08-20 15:14
from __future__ import annotations

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
('api', '0010_auditrecord'),
]

operations = [
migrations.RemoveField(
model_name='asset',
name='previous',
),
]
7 changes: 0 additions & 7 deletions dandiapi/api/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ class Status(models.TextChoices):
choices=Status.choices,
)
validation_errors = models.JSONField(default=list, blank=True, null=True)
previous = models.ForeignKey(
'Asset',
blank=True,
null=True,
default=None,
on_delete=models.SET_NULL,
)
published = models.BooleanField(default=False)

class Meta:
Expand Down
4 changes: 0 additions & 4 deletions dandiapi/api/services/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ def change_asset( # noqa: PLR0913
metadata=new_metadata,
)

# Set previous asset and save
new_asset.previous = asset
new_asset.save()

audit.update_asset(dandiset=version.dandiset, user=user, asset=new_asset)
Copy link
Member

Choose a reason for hiding this comment

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

So just to be clear, with this change, the only way to relate an audit event to an asset is through it's path metadata field, correct? Since the old asset metadata isn't tracked, just the new one?


return new_asset, True
Expand Down
9 changes: 0 additions & 9 deletions dandiapi/api/tests/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,9 +1108,6 @@ def test_asset_rest_update(api_client, user, draft_version, asset, asset_blob):
new_asset = Asset.objects.get(asset_id=resp['asset_id'])
assert new_asset in draft_version.assets.all()

# The new asset should have a reference to the old asset
assert new_asset.previous == asset

# Ensure new path is ingested
assert not AssetPath.objects.filter(path=old_path, version=draft_version).exists()
assert AssetPath.objects.filter(path=new_path, version=draft_version).exists()
Expand Down Expand Up @@ -1168,9 +1165,6 @@ def test_asset_rest_update_embargo(api_client, user, draft_version, asset, embar
new_asset = Asset.objects.get(asset_id=resp['asset_id'])
assert new_asset in draft_version.assets.all()

# The new asset should have a reference to the old asset
assert new_asset.previous == asset

# The version modified date should be updated
start_time = draft_version.modified
draft_version.refresh_from_db()
Expand Down Expand Up @@ -1266,9 +1260,6 @@ def test_asset_rest_update_zarr(
new_asset = Asset.objects.get(asset_id=resp['asset_id'])
assert new_asset in draft_version.assets.all()

# The new asset should have a reference to the old asset
assert new_asset.previous == asset

# The version modified date should be updated
start_time = draft_version.modified
draft_version.refresh_from_db()
Expand Down