{"action":"closed","issue":{"url":"https://api.github.com/repos/roundware/roundware-server/issues/291","repository_url":"https://api.github.com/repos/roundware/roundware-server","labels_url":"https://api.github.com/repos/roundware/roundware-server/issues/291/labels{/name}","comments_url":"https://api.github.com/repos/roundware/roundware-server/issues/291/comments","events_url":"https://api.github.com/repos/roundware/roundware-server/issues/291/events","html_url":"https://github.com/roundware/roundware-server/issues/291","id":165452586,"number":291,"title":"auth_permission rows get \"duplicated\" on ./deploy.sh","user":{"login":"IllyaMoskvin","id":3881840,"avatar_url":"https://avatars.githubusercontent.com/u/3881840?v=3","gravatar_id":"","url":"https://api.github.com/users/IllyaMoskvin","html_url":"https://github.com/IllyaMoskvin","followers_url":"https://api.github.com/users/IllyaMoskvin/followers","following_url":"https://api.github.com/users/IllyaMoskvin/following{/other_user}","gists_url":"https://api.github.com/users/IllyaMoskvin/gists{/gist_id}","starred_url":"https://api.github.com/users/IllyaMoskvin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IllyaMoskvin/subscriptions","organizations_url":"https://api.github.com/users/IllyaMoskvin/orgs","repos_url":"https://api.github.com/users/IllyaMoskvin/repos","events_url":"https://api.github.com/users/IllyaMoskvin/events{/privacy}","received_events_url":"https://api.github.com/users/IllyaMoskvin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-14T00:40:09Z","updated_at":"2016-07-27T02:43:55Z","closed_at":"2016-07-27T02:43:55Z","body":"As of at least fadb34d, there is a major problem with the `default_auth.json` fixture. Almost all `auth.permission` objects contain outdated `content_type` references. Running `python manage.py migrate` after a fresh install causes \"duplicate\" references to content types in the `auth_permission` table. This also happens if you run `./deploy.sh` at any time.\r\n\r\nSpecifically, permissions for content types that changed ids get duplicated. For instance, `access_project` in `default_auth` points to `content_type: 13`; therefore, the following row gets created in `auth_permission`:\r\n\r\n    40 | Access Project                     |              13 | access_project\r\n\r\nHowever, after a fresh install, in the `django_content_type` table, `project` has an id of 16. Therefore, a second row gets created in `auth_permission`:\r\n\r\n    128 | Access Project                       |              16 | access_project\r\n\r\nThis occurs for all permissions for that content type:\r\n\r\n    37 | Can add project                      |              13 | add_project\r\n    38 | Can change project                   |              13 | change_project\r\n    39 | Can delete project                   |              13 | delete_project\r\n    40 | Access Project                       |              13 | access_project\r\n    ...\r\n    125 | Can add project                      |              16 | add_project\r\n    126 | Can change project                   |              16 | change_project\r\n    127 | Can delete project                   |              16 | delete_project\r\n    128 | Access Project                       |              16 | access_project\r\n\r\nPermissions for content types whose id matches that listed in `default_auth.json` do not get duplicated:\r\n\r\n     1 | Can add permission                   |               1 | add_permission\r\n     2 | Can change permission                |               1 | change_permission\r\n     3 | Can delete permission                |               1 | delete_permission\r\n\r\nThis problem has been present for a long time; however, Django managed to work around it by referencing only the permissions for the new content type id. Now that we are using custom `django-guardian` permissions in the APIv2 branch, this issue is rearing its ugly head.\r\n\r\nFor anyone who stumbles on this page while troubleshooting your own projects, if you are using `auth.permission` fixtures with `django-guardian`, and if you get errors similar to the one below, check `auth_permission` for orphaned `content_type` references:\r\n\r\n    File \"/var/www/roundware/source/roundware/rw/admin.py\", line 99, in get_queryset\r\n      return qset.filter(project__in=get_objects_for_user(request.user, 'rw.access_project'))\r\n    File \"/usr/local/lib/python2.7/dist-packages/guardian/shortcuts.py\", line 441, in get_objects_for_user\r\n      permission__codename=codename)\r\n    File \"/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py\", line 122, in manager_method\r\n      return getattr(self.get_queryset(), name)(*args, **kwargs)\r\n    File \"/usr/local/lib/python2.7/dist-packages/django/db/models/query.py\", line 391, in get\r\n      (self.model._meta.object_name, num)\r\n    MultipleObjectsReturned: get() returned more than one ContentType -- it returned 2!\r\n\r\nI'm still trying to figure out what to do about this. My tentative recommendation is to do away with the `auth.permission` fixtures in `default_auth.json` and just let Django fill out the table as it sees fit. Furthermore, we should consider truncating the `auth_permission` table as part of the upgrade process to Django 1.9 (#283)."}}
{"actor":{"display_login":"hburgund"}}