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.233%. remained the same
when pulling c677875 on 12030-unable-to-delete-dataverse-with-metrics
into fd75558 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
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: 3 A percentage of a sprint. 2.1 hours. Type: Bug a defect

Projects

Status: Ready for Review ⏩

Development

Successfully merging this pull request may close these issues.

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

4 participants