RunestoneServer icon indicating copy to clipboard operation
RunestoneServer copied to clipboard

Endpoint /admin/deletecourse failures

Open bjones1 opened this issue 3 years ago • 4 comments

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?

bjones1 avatar Feb 26 '22 03:02 bjones1

I'm skipping this test for now until we have an idea on how to solve this.

bjones1 avatar Feb 26 '22 03:02 bjones1

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.

bnmnetp avatar Mar 06 '22 23:03 bnmnetp

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.

bjones1 avatar Mar 08 '22 21:03 bjones1

Stale issue message

github-actions[bot] avatar Jun 07 '22 02:06 github-actions[bot]

Stale issue message

github-actions[bot] avatar Sep 13 '22 02:09 github-actions[bot]