The SIO2 project
  1. The SIO2 project
  2. SIO-1854

IntegrityError when removing a contest after disabling gamification

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Current Version
    • Fix Version/s: TAG 2016/17 Sprint 1
    • Component/s: OIOIOI
    • Labels:

      Description

      Internal Server Error: /c/2a_rozne/admin/contests/contest/2a_rozne/delete/
      Traceback (most recent call last):
        File "/home/users/sio2/sio2/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
          response = wrapped_callback(request, *callback_args, **callback_kwargs)
        File "/home/users/sio2/sio2/venv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 145, in inner
          return func(*args, **kwargs)
        File "/home/users/sio2/sio2/venv/local/lib/python2.7/site-packages/django/db/transaction.py", line 225, in __exit__
          connection.commit()
        File "/home/users/sio2/sio2/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 173, in commit
          self._commit()
        File "/home/users/sio2/sio2/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 142, in _commit
          return self.connection.commit()
        File "/home/users/sio2/sio2/venv/local/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
          six.reraise(dj_exc_type, dj_exc_value, traceback)
        File "/home/users/sio2/sio2/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 142, in _commit
          return self.connection.commit()
      IntegrityError: update or delete on table "problems_problem" violates foreign key constraint "gamification_problem_id_6c405b0a31bad73a_fk_problems_problem_id" on table "gamification_problemdifficulty"
      DETAIL: Key (id)=(11080) is still referenced from table "gamification_problemdifficulty".

      The solution is to add ON CASCADE DELETE in the Django models for gamification.

        Issue Links

          Activity

          Hide
          Szymon Acedański added a comment -
          I think it's actually better to drop gamification altogether and fix the IntegrityError in the production by hand.
          Show
          Szymon Acedański added a comment - I think it's actually better to drop gamification altogether and fix the IntegrityError in the production by hand.
          Hide
          Gerrit Gerrit added a comment -
          Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 1
          https://gerrit.sio2project.mimuw.edu.pl/2654

          SIO-1854 IntegrityError when removing a contest after disabling gamification

          Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Show
          Gerrit Gerrit added a comment - Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 1 https://gerrit.sio2project.mimuw.edu.pl/2654 SIO-1854 IntegrityError when removing a contest after disabling gamification Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Hide
          Gerrit Gerrit added a comment -
          Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 2
          https://gerrit.sio2project.mimuw.edu.pl/2654

          SIO-1854 IntegrityError when removing a contest after disabling gamification

          Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Show
          Gerrit Gerrit added a comment - Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 2 https://gerrit.sio2project.mimuw.edu.pl/2654 SIO-1854 IntegrityError when removing a contest after disabling gamification Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Hide
          Gerrit Gerrit added a comment -
          Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 3
          https://gerrit.sio2project.mimuw.edu.pl/2654

          SIO-1854 IntegrityError when removing a contest after disabling gamification

          Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Show
          Gerrit Gerrit added a comment - Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 3 https://gerrit.sio2project.mimuw.edu.pl/2654 SIO-1854 IntegrityError when removing a contest after disabling gamification Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Hide
          Gerrit Gerrit added a comment -
          Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 4
          https://gerrit.sio2project.mimuw.edu.pl/2654

          SIO-1854 IntegrityError when removing a contest after disabling gamification

          Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Show
          Gerrit Gerrit added a comment - Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 4 https://gerrit.sio2project.mimuw.edu.pl/2654 SIO-1854 IntegrityError when removing a contest after disabling gamification Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Hide
          Gerrit Gerrit added a comment -
          Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 5
          https://gerrit.sio2project.mimuw.edu.pl/2654

          SIO-1854 IntegrityError when removing a contest after disabling gamification

          Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Show
          Gerrit Gerrit added a comment - Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 5 https://gerrit.sio2project.mimuw.edu.pl/2654 SIO-1854 IntegrityError when removing a contest after disabling gamification Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Hide
          Gerrit Gerrit added a comment -
          Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 6
          https://gerrit.sio2project.mimuw.edu.pl/2654

          SIO-1854 IntegrityError when removing a contest after disabling gamification

          Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Show
          Gerrit Gerrit added a comment - Change I984f4264272dd4bd48c829a0aa741384659d1dda, patchset 6 https://gerrit.sio2project.mimuw.edu.pl/2654 SIO-1854 IntegrityError when removing a contest after disabling gamification Change-Id: I984f4264272dd4bd48c829a0aa741384659d1dda
          Hide
          Szymon Pajzert added a comment -
          Using query below I found all foreign keys in gamification app. Then I changed their constraints in a similar manner:

          ALTER TABLE gamification_friendshiprequest DROP CONSTRAINT ga_recipient_id_6aa97b97fddd3897_fk_gamification_friendproxy_id;
          ALTER TABLE gamification_friendshiprequest ADD CONSTRAINT ga_recipient_id_6aa97b97fddd3897_fk_gamification_friendproxy_id
          FOREIGN KEY(recipient_id) REFERENCES gamification_friendproxy(id) ON DELETE CASCADE;

          I did this for 9 constraints:
           gamification_cachedexp_user_id_61c4fabafae25fee_fk_auth_user_id in gamification_cachedexperiencesourceid(user_id)
           gamification_cachedexpe_user_id_595952a5cc2b64c_fk_auth_user_id in gamification_cachedexperiencesourcetotal(user_id)
           gamification_friendpro_user_id_5dcb59a46d383d73_fk_auth_user_id in gamification_friendproxy(user_id)
           gamification_codeshari_user_id_53e21a9acebbf9cf_fk_auth_user_id in gamification_codesharingsettings(user_id)
           gamification_problem_id_6c405b0a31bad73a_fk_problems_problem_id in gamification_problemdifficulty(problem_id)
           D74f9b12b6df791a0be19d26bb443c15 in gamification_friendproxy_friends(to_friendproxy_id)
           ga_recipient_id_6aa97b97fddd3897_fk_gamification_friendproxy_id in gamification_friendshiprequest(recipient_id)
           gamif_sender_id_72727873c24c92fe_fk_gamification_friendproxy_id in gamification_friendshiprequest(sender_id)
           D192f4a50771c6dc4f935b1766f00956 in gamification_friendproxy_friends(from_friendproxy_id)


          Here's SQL query

          SELECT
              tc.constraint_name, tc.table_name, kcu.column_name,
              ccu.table_name AS foreign_table_name,
              ccu.column_name AS foreign_column_name
          FROM
              information_schema.table_constraints AS tc
              JOIN information_schema.key_column_usage AS kcu
                ON tc.constraint_name = kcu.constraint_name
              JOIN information_schema.constraint_column_usage AS ccu
                ON ccu.constraint_name = tc.constraint_name
          WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name like 'gamification_%';
          Show
          Szymon Pajzert added a comment - Using query below I found all foreign keys in gamification app. Then I changed their constraints in a similar manner: ALTER TABLE gamification_friendshiprequest DROP CONSTRAINT ga_recipient_id_6aa97b97fddd3897_fk_gamification_friendproxy_id; ALTER TABLE gamification_friendshiprequest ADD CONSTRAINT ga_recipient_id_6aa97b97fddd3897_fk_gamification_friendproxy_id FOREIGN KEY(recipient_id) REFERENCES gamification_friendproxy(id) ON DELETE CASCADE; I did this for 9 constraints:  gamification_cachedexp_user_id_61c4fabafae25fee_fk_auth_user_id in gamification_cachedexperiencesourceid(user_id)  gamification_cachedexpe_user_id_595952a5cc2b64c_fk_auth_user_id in gamification_cachedexperiencesourcetotal(user_id)  gamification_friendpro_user_id_5dcb59a46d383d73_fk_auth_user_id in gamification_friendproxy(user_id)  gamification_codeshari_user_id_53e21a9acebbf9cf_fk_auth_user_id in gamification_codesharingsettings(user_id)  gamification_problem_id_6c405b0a31bad73a_fk_problems_problem_id in gamification_problemdifficulty(problem_id)  D74f9b12b6df791a0be19d26bb443c15 in gamification_friendproxy_friends(to_friendproxy_id)  ga_recipient_id_6aa97b97fddd3897_fk_gamification_friendproxy_id in gamification_friendshiprequest(recipient_id)  gamif_sender_id_72727873c24c92fe_fk_gamification_friendproxy_id in gamification_friendshiprequest(sender_id)  D192f4a50771c6dc4f935b1766f00956 in gamification_friendproxy_friends(from_friendproxy_id) Here's SQL query SELECT     tc.constraint_name, tc.table_name, kcu.column_name,     ccu.table_name AS foreign_table_name,     ccu.column_name AS foreign_column_name FROM     information_schema.table_constraints AS tc     JOIN information_schema.key_column_usage AS kcu       ON tc.constraint_name = kcu.constraint_name     JOIN information_schema.constraint_column_usage AS ccu       ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name like 'gamification_%';

            People

            • Assignee:
              Szymon Acedański
              Reporter:
              Szymon Acedański
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: