Skip to content

feat: prevent draft creation for unchanged dataset metadata#12452

Open
AnneGerlach wants to merge 1 commit into
IQSS:developfrom
AnneGerlach:feat/12376-skip-empty-drafts-for-unchanged-metadata
Open

feat: prevent draft creation for unchanged dataset metadata#12452
AnneGerlach wants to merge 1 commit into
IQSS:developfrom
AnneGerlach:feat/12376-skip-empty-drafts-for-unchanged-metadata

Conversation

@AnneGerlach

Copy link
Copy Markdown

What this PR does / why we need it:

🎫 Closes: #12376

This PR prevents Dataverse from creating or updating a draft version when metadata uploaded via PUT /api/datasets/{id}/versions/:draft is semantically identical to the existing dataset version.

Previously, repeated uploads of unchanged metadata created unnecessary draft versions. This was particularly problematic for automated synchronization workflows, which had to implement their own comparison logic before submitting updates.

The implementation reuses the existing DatasetVersionDifference logic to detect unchanged metadata and terms updates and skips draft creation or update when no effective changes are detected.

Changes

  • Added a no-op check before draft creation and draft update in PUT /api/datasets/{id}/versions/:draft

  • Reused the existing DatasetVersionDifference implementation to detect unchanged metadata and terms updates

  • Skipped draft creation/update and returned the existing dataset version when no effective changes are detected

  • Added integration tests covering both scenarios:

    • no draft exists
    • draft already exists

Suggestions on how to test this:

Run tests:

mvn test -Dtest=DatasetsTest,DatasetsIT

or tests manually:

Test no-op metadata update

  1. Login as dataverseAdmin
  2. Create and publish a dataset via the UI
  3. Generate an API token and copy the dataset PID (export those: API_TOKEN and PID)
# Download latest version metadata
curl -H "X-Dataverse-key: $API_TOKEN" \
"http://localhost:8080/api/datasets/:persistentId?persistentId=$PID" \
| jq '.data.latestVersion' > latestVersion.json
# Re-upload unchanged metadata
curl -X PUT \
-H "X-Dataverse-key: $API_TOKEN" \
-H "Content-Type: application/json" \
--data @latestVersion.json \
"http://localhost:8080/api/datasets/:persistentId/versions/:draft?persistentId=$PID"
# Verify no draft was created
curl -H "X-Dataverse-key: $API_TOKEN" \
"http://localhost:8080/api/datasets/:persistentId/versions?persistentId=$PID" \
| jq

Test changed metadata

# Modify metadata in the file e.g.
nano latestVersion.json
# Upload changed metadata
curl -X PUT \
-H "X-Dataverse-key: $API_TOKEN" \
-H "Content-Type: application/json" \
--data @latestVersion.json \
"http://localhost:8080/api/datasets/:persistentId/versions/:draft?persistentId=$PID"
# Verify draft now exists
curl -H "X-Dataverse-key: $API_TOKEN" \
"http://localhost:8080/api/datasets/:persistentId/versions?persistentId=$PID" \
| jq

Special notes for your reviewer:

Thanks for reviewing 🌻 (and special thanks to @vera for reviewing beforehand 🌷 )

@pdurbin pdurbin moved this to Ready for Triage in IQSS Dataverse Project Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for Triage

Development

Successfully merging this pull request may close these issues.

2 participants