Skip to content

Commit

Permalink
Fix slug generation
Browse files Browse the repository at this point in the history
Slugs are intended to be human-readable and unique for an artifact.
However when a user submitted multiple versions they often got
duplicated slugs. This was because our check for an existing version was
based on the artifacts date, not the version date.

We attempted to fix in #133, but the issue persisted. I just happened to
notice this filter code seemed wrong.
  • Loading branch information
Mark-Powers committed Nov 11, 2024
1 parent 517657b commit 864ebae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion trovi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def generate_slug(instance: "ArtifactVersion", created: bool = False, **_):
with transaction.atomic():
if instance.artifact:
versions_today_query = instance.artifact.versions.filter(
artifact__created_at__date=instance.created_at.date(),
created_at__date=instance.created_at.date(),
).select_for_update()
versions_today = versions_today_query.exclude(
slug__exact=""
Expand Down
4 changes: 3 additions & 1 deletion trovi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
import sys
from urllib.parse import urlparse

BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -191,8 +192,9 @@

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
TESTING = "test" in sys.argv or "test_coverage" in sys.argv

if os.getenv("DB_ENGINE"):
if not TESTING and os.getenv("DB_ENGINE"):
DATABASES = {
"default": {
"ENGINE": os.getenv("DB_ENGINE"),
Expand Down
2 changes: 2 additions & 0 deletions util/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def fake_tag() -> str:
is_reproducible=True,
repro_access_hours=3,
)
artifact_don_quixote.created_at -= datetime.timedelta(days=2)

version_don_quixote_1 = ArtifactVersion(
artifact=artifact_don_quixote,
contents_urn=f"urn:trovi:contents:chameleon:{uuid4()}",
Expand Down

0 comments on commit 864ebae

Please sign in to comment.