Skip to content

Conversation

@stevenwinship
Copy link
Contributor

What this PR does / why we need it: dataverse delete fails if there are cached metrics due to a foreign key constraint

Which issue(s) this PR closes: #12030

Special notes for your reviewer:

Suggestions on how to test this: create/publish dataverse. request metrics to cause a cached row in metric table. Delete the dataverse

Does this PR introduce a user interface change? If mockups are available, please link/include them here:

Is there a release notes update needed for this change?:

Additional documentation:

@stevenwinship stevenwinship self-assigned this Dec 9, 2025
@stevenwinship stevenwinship added Type: Bug a defect Size: 3 A percentage of a sprint. 2.1 hours. labels Dec 9, 2025
@stevenwinship stevenwinship moved this to In Progress 💻 in IQSS Dataverse Project Dec 9, 2025
@coveralls
Copy link

coveralls commented Dec 9, 2025

Coverage Status

coverage: 24.314%. remained the same
when pulling 88d280d on 12030-unable-to-delete-dataverse-with-metrics
into f214ee4 on develop.

@github-actions

This comment has been minimized.

@@ -0,0 +1,2 @@
ALTER TABLE metric DROP CONSTRAINT fk_metric_dataverse_id;
ALTER TABLE metric ADD CONSTRAINT fk_metric_dataverse_id FOREIGN KEY (dataverse_id) REFERENCES dataverse(id) ON DELETE CASCADE;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this would usually be generated (with the ON DELETE CASCADE part) - the Cascade remove annotation works at the ORM layer. At least I haven't seen it before looking at the table descriptions for other places we have cascade remove annotations. I guess I'd suggest seeing if the remove works without changing the db constraint if you haven't already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I re-tested everything and the annotation on Metric didn't do anything. The only change that works is the constraint change in this sql

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested both with upgraded db/dataverse and new db

Copy link
Member

Choose a reason for hiding this comment

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

Hmm - that seems like a problem - what annotations did you try? Orphan?

Copy link
Member

Choose a reason for hiding this comment

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

Are we missing the equivalent of

@OneToMany(mappedBy = "dataset", orphanRemoval = true, cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST})
private List<DatasetMetrics> datasetMetrics = new ArrayList<>();
for Dataverse/Metric ?

Copy link
Contributor Author

@stevenwinship stevenwinship Dec 12, 2025

Choose a reason for hiding this comment

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

yes. Dataverse doesn't have that. There is no DataverseMetrics class

Copy link
Contributor Author

@stevenwinship stevenwinship Dec 12, 2025

Choose a reason for hiding this comment

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

added
@OneToMany(mappedBy = "dataverse", orphanRemoval = true, cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST}) private List<Metric> dataverseMetrics = new ArrayList<>();

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@stevenwinship stevenwinship moved this from In Progress 💻 to Ready for Review ⏩ in IQSS Dataverse Project Dec 12, 2025
@stevenwinship stevenwinship removed their assignment Dec 12, 2025
@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@cmbz cmbz added FY26 Sprint 12 FY26 Sprint 12 (2025-12-03 - 2025-12-17) FY26 Sprint 13 FY26 Sprint 13 (2025-12-17 - 2025-12-31) labels Dec 17, 2025
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@cmbz cmbz added the FY26 Sprint 14 FY26 Sprint 14 (2025-12-31 - 2026-01-14) label Dec 31, 2025
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@cmbz cmbz added the FY26 Sprint 15 FY26 Sprint 15 (2026-01-14 - 2026-01-28) label Jan 15, 2026
@github-actions
Copy link

📦 Pushed preview images as

ghcr.io/gdcc/dataverse:12030-unable-to-delete-dataverse-with-metrics
ghcr.io/gdcc/configbaker:12030-unable-to-delete-dataverse-with-metrics

🚢 See on GHCR. Use by referencing with full name as printed above, mind the registry name.

Copy link
Member

@qqmyers qqmyers left a comment

Choose a reason for hiding this comment

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

Seems reasonable. I wonder if we actually need the cascade parts since we don't create metrics via the Dataverse object. (Same for Dataset probably). That said, it should work as written.

@github-project-automation github-project-automation bot moved this from Ready for Review ⏩ to Ready for QA ⏩ in IQSS Dataverse Project Jan 18, 2026
@sekmiller sekmiller moved this from Ready for QA ⏩ to QA ✅ in IQSS Dataverse Project Jan 20, 2026
@sekmiller sekmiller self-assigned this Jan 20, 2026
@sekmiller
Copy link
Contributor

It does what it purports to do. - if there are records on the metric table I can still delete the dataverse and the metric record is also deleted.
I did find a couple of anomalies with the get Metrics API. If you call it with a parentAlias that exists but isn't published it will return a value (in my case the total number of dataverses in my local db). It doesn't create a record in the metric table. If you call it with a parentAlias that doesn't exist you get an "Api endpoint doesn't exist error" not a dataverse not found error. Out of scope for this, but possibly worth fixing?

@sekmiller sekmiller merged commit fadbfdd into develop Jan 20, 2026
20 checks passed
@github-project-automation github-project-automation bot moved this from QA ✅ to Merged 🚀 in IQSS Dataverse Project Jan 20, 2026
@stevenwinship stevenwinship deleted the 12030-unable-to-delete-dataverse-with-metrics branch January 20, 2026 22:15
@pdurbin pdurbin added this to the 6.10 milestone Jan 21, 2026
@scolapasta scolapasta moved this from Merged 🚀 to Done 🧹 in IQSS Dataverse Project Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FY26 Sprint 12 FY26 Sprint 12 (2025-12-03 - 2025-12-17) FY26 Sprint 13 FY26 Sprint 13 (2025-12-17 - 2025-12-31) FY26 Sprint 14 FY26 Sprint 14 (2025-12-31 - 2026-01-14) FY26 Sprint 15 FY26 Sprint 15 (2026-01-14 - 2026-01-28) Size: 3 A percentage of a sprint. 2.1 hours. Type: Bug a defect

Projects

Status: Done 🧹

Development

Successfully merging this pull request may close these issues.

Unable to delete Dataverse when a row exists in the metrics table

7 participants