Endpoint /admin/deletecourse failures
Working on getting the unit tests to work. I see a failure when testing the test_build function in tests/test_designer.py . It produces the following exception:
ForeignKeyViolation(update or delete on table "courses" violates foreign key constraint "useinfo_course_id_fkey" on table "useinfo" DETAIL: Key (course_name)=(build_course_1) is still referenced from table "useinfo".
I assume this is because of the following constraint in BookServer/models.py:
course_id = Column(
String(512), ForeignKey("courses.course_name"), index=True, nullable=False
)
The only way around this I see is to delete all the data associated with this course -- from useinfo, all the xxx_answer tables, etc. Aack! This would be difficult and involve removing a LOT of data that we couldn't easily recover, perhaps creating some very unhappy instructors. @bnmnetp, any thoughts on a way forward?
I'm skipping this test for now until we have an idea on how to solve this.
We could change the foreign key constraint so that it has an on delete cascade clause.
Or we could remove the constraint. When we migrated the model you/we added a lot of these, but I don't think we reviewed that very thoroughly. For example we have a foreign key on course_id in useinfo but not on div_id or sid Both of which are foreign keys to questions and auth_user respectively.
I'm not sure what the best path is... If an instructor deletes a course then all of its data should be gone. I didn't do this before because it destroys valuable research data. At the same time I know some schools want data deleted X months after the class is over.
Thinking about this, I'm in favor of deleting all the data if the instructor requests it -- this gives them control over their data. I'd also suggest adding more foreign keys, so we ensure things stay properly linked together.
Stale issue message
Stale issue message