-
-
Notifications
You must be signed in to change notification settings - Fork 1k
SAK-52322 Samigo fix FK on SAM_EXTENDEDTIME_T blocks delete of publis… #14356
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
base: master
Are you sure you want to change the base?
Conversation
…hed assessment during site import cleanup
WalkthroughIntroduces batch deletion functionality for ExtendedTime entries across the assessment facade layer. A new public method Changes
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Failure to add the new IP will result in interrupted reviews. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@samigo/samigo-services/src/java/org/sakaiproject/tool/assessment/facade/PublishedAssessmentFacadeQueries.java`:
- Around line 1867-1871: The call to
ExtendedTimeFacade.deleteEntriesForPub(data) currently ignores its boolean
return value; change the logic in the deletion block so that you check the
boolean result from ExtendedTimeFacade.deleteEntriesForPub(...) and abort the
published-assessment deletion if it returns false (do not call
getHibernateTemplate().delete(data) on failure). Use the existing
ExtendedTimeFacade reference (ExtendedTimeFacade extendedTimeFacade =
PersistenceService.getInstance().getExtendedTimeFacade()), the
deleteEntriesForPub(...) result, and the getHibernateTemplate().delete(data)
call to gate the deletion (e.g., return/throw/propagate an error when cleanup
fails) so FK/orphan issues are avoided.
| ExtendedTimeFacade extendedTimeFacade = PersistenceService.getInstance().getExtendedTimeFacade(); | ||
| if (extendedTimeFacade != null) { | ||
| extendedTimeFacade.deleteEntriesForPub(data); | ||
| } | ||
| getHibernateTemplate().delete(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abort deletion when ExtendedTime cleanup fails.
deleteEntriesForPub returns a boolean but the result is ignored. If cleanup fails, you can still attempt to delete the published assessment, which risks FK violations or orphaned ExtendedTime rows. Consider failing fast when cleanup fails.
✅ Suggested fix
ExtendedTimeFacade extendedTimeFacade = PersistenceService.getInstance().getExtendedTimeFacade();
if (extendedTimeFacade != null) {
- extendedTimeFacade.deleteEntriesForPub(data);
+ boolean extendedTimeDeleted = extendedTimeFacade.deleteEntriesForPub(data);
+ if (!extendedTimeDeleted) {
+ log.warn("Unable to delete ExtendedTime entries for published assessment id: {}", data.getPublishedAssessmentId());
+ throw new IllegalStateException("Failed to delete ExtendedTime entries for published assessment id " + data.getPublishedAssessmentId());
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ExtendedTimeFacade extendedTimeFacade = PersistenceService.getInstance().getExtendedTimeFacade(); | |
| if (extendedTimeFacade != null) { | |
| extendedTimeFacade.deleteEntriesForPub(data); | |
| } | |
| getHibernateTemplate().delete(data); | |
| ExtendedTimeFacade extendedTimeFacade = PersistenceService.getInstance().getExtendedTimeFacade(); | |
| if (extendedTimeFacade != null) { | |
| boolean extendedTimeDeleted = extendedTimeFacade.deleteEntriesForPub(data); | |
| if (!extendedTimeDeleted) { | |
| log.warn("Unable to delete ExtendedTime entries for published assessment id: {}", data.getPublishedAssessmentId()); | |
| throw new IllegalStateException("Failed to delete ExtendedTime entries for published assessment id " + data.getPublishedAssessmentId()); | |
| } | |
| } | |
| getHibernateTemplate().delete(data); |
🤖 Prompt for AI Agents
In
`@samigo/samigo-services/src/java/org/sakaiproject/tool/assessment/facade/PublishedAssessmentFacadeQueries.java`
around lines 1867 - 1871, The call to
ExtendedTimeFacade.deleteEntriesForPub(data) currently ignores its boolean
return value; change the logic in the deletion block so that you check the
boolean result from ExtendedTimeFacade.deleteEntriesForPub(...) and abort the
published-assessment deletion if it returns false (do not call
getHibernateTemplate().delete(data) on failure). Use the existing
ExtendedTimeFacade reference (ExtendedTimeFacade extendedTimeFacade =
PersistenceService.getInstance().getExtendedTimeFacade()), the
deleteEntriesForPub(...) result, and the getHibernateTemplate().delete(data)
call to gate the deletion (e.g., return/throw/propagate an error when cleanup
fails) so FK/orphan issues are avoided.
…hed assessment during site import cleanup
Summary by CodeRabbit
Release Notes