Ticket #223 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Deleting a subject which has samples causes problems at the event stage

Reported by: business@… Owned by: kees.vanbochove@…
Priority: major Milestone: 0.6.2
Component: Study create/edit wizard Version:
Keywords: Cc:
Product: Operating system:
URL: Hardware:

Description

Steps to reproduce:

1. Go to test.nmcdsp.org and login as user
2. Edit study Example study
3. Hit next on the study information
4. Delete Subject 2 (Greenhouse plant template)
5. Hit next to go on to the events
6. All looks well, so hit next
7. And now all of a sudden it gives an (incorrect) error message that the sample template is null
8. After that, if you try to go on, the sampling event properties are deleted (also the group assignments)
9. If you try to repair it by re-assigning the sampling event to both groups and choosing again the sample template, you can go on, even the samples will be correctly generated, but upon saving you get the error:

exception → org.springframework.dao.InvalidDataAccessApiUsageException?: deleted object would be re-saved by cascade (remove deleted object from associations): [dbnp.studycapturing.Sample#52]; nested exception is org.hibernate.ObjectDeletedException?: deleted object would be re-saved by cascade (remove deleted object from associations): [dbnp.studycapturing.Sample#52], see log for stacktrace

Change History

Changed 3 years ago by work@…

I can indeed reproduce this issue on test, but I need to be able to reproduce on dev as well. Do you have steps to reproduce this issue on dev as well?

Changed 3 years ago by work@…

If you do this, the problem does NOT happen:

1. in the study page click next
2. in the subject page click next
3. in the event page click previous
4. in the subject page delete subject 2 and click next
5. in the event page click next

no exception...

Changed 3 years ago by work@…

Situation 1: do not delete subject 2 in subject page
Situation 2: delete subject 2 in subject page

In the case of situation 2 the POST variables differ from the object instances (the identity has changed after deleting the subject?).

Situation 1, event page: Harvest Event identity is the same as the ID in the POST vars
Situation 2, event page: Harvest Event identity differs in POST vars from object instance. Hence, 'null' is not allowed at object validation.

Question remains: why does the samplingEvent (harvest) instance change when deleting a subject?

-- snip:

// Delete the subject from the event groups it was referenced in
this.eventGroups.each {

if (it.subjects.contains(subject)) {

it.removeFromSubjects(subject)
msg += ", deleted from event group '${it.name}'"

}

}

Changed 3 years ago by business@…

Alternatively, it might be caused by:

		// Delete the samples that have this subject as parent
		this.samples.findAll { it.parentSubject.equals(subject) }.each {
			// This should remove the sample itself too, because of the cascading belongsTo relation
			this.removeFromSamples(it)
			// But apparently it needs an explicit delete() too
			it.delete()
			msg += ", sample '${it.name}' was deleted"
		}

There seems to be one sample, which should have the problematic sampling event as parent event. That's the only relation I could think of that this subject has to the sampling event, apart from the event group you already mentioned.

Changed 3 years ago by work@…

  • status changed from new to assigned
  • owner changed from work@… to business@…

Resolved in r1225

Grails automatically instantiates classes when required. That works perfectly well in the create study wizard, but in the edit study wizard this apparently leads to issues. The issue above is caused that the SamplingEvent? instance is 'refreshed' resulting in a different identity (@see the Identity class). While this works perfectly fine when you do not use complex forms (hence: no identity), this results in issues when you do.

Workaround is to force grails to load all 'hasmany' fields when you start editing a study.

I have deployed the fix on test.nmcdsp.org, please retest...

Changed 3 years ago by work@…

This also fixed #147 ! Yay! :D

Changed 3 years ago by work@…

improved documentation in r1227

Changed 3 years ago by business@…

  • owner changed from business@… to work@…

I still get the error on test.nmcdsp.org when I follow these steps... Is it redeployed correctly?

Changed 3 years ago by work@…

revision : 1225
Grails version : 1.3.4
Groovy version : 1.7.4
JVM version : 1.6.0_20
deployed : November 30, 2010 5:29:42 PM GMT+01:00
uptime : 1d, 21h, 32m, 21s

It doesn't seem so... I'll redeploy...

Changed 3 years ago by work@…

  • owner changed from work@… to kees.vanbochove@…

it should work now... please confirm...

Changed 3 years ago by work@…

Still samples were not deleted properly. Introduced a 'deleteSample' method in r1233 which resolved the issue on the test instance. I'd ask you to retest if it was possible, but the issue is fixed...

Assigning back to Kees, so he can close the issue...

Changed 3 years ago by business@…

  • status changed from assigned to closed
  • resolution set to fixed

Apparently fixed. (NB use business@...)

Note: See TracTickets for help on using tickets.