{"action":"created","issue":{"url":"https://api.github.com/repos/dfunckt/django-rules/issues/46","repository_url":"https://api.github.com/repos/dfunckt/django-rules","labels_url":"https://api.github.com/repos/dfunckt/django-rules/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/dfunckt/django-rules/issues/46/comments","events_url":"https://api.github.com/repos/dfunckt/django-rules/issues/46/events","html_url":"https://github.com/dfunckt/django-rules/issues/46","id":189757574,"number":46,"title":"AttributeError: 'ObjectPermissionBackend' object has no attribute 'get_user'","user":{"login":"blueyed","id":9766,"avatar_url":"https://avatars.githubusercontent.com/u/9766?v=3","gravatar_id":"","url":"https://api.github.com/users/blueyed","html_url":"https://github.com/blueyed","followers_url":"https://api.github.com/users/blueyed/followers","following_url":"https://api.github.com/users/blueyed/following{/other_user}","gists_url":"https://api.github.com/users/blueyed/gists{/gist_id}","starred_url":"https://api.github.com/users/blueyed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blueyed/subscriptions","organizations_url":"https://api.github.com/users/blueyed/orgs","repos_url":"https://api.github.com/users/blueyed/repos","events_url":"https://api.github.com/users/blueyed/events{/privacy}","received_events_url":"https://api.github.com/users/blueyed/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-16T16:24:27Z","updated_at":"2016-11-23T14:42:57Z","closed_at":"2016-11-16T16:38:25Z","body":"I am trying to use Django's `Client.force_login` during tests, which appears to trigger an `AttributeError` when using `ObjectPermissionBackend` in `settings.AUTHENTICATION_BACKENDS`:\r\n\r\n    [25]   …/app/tests/test_middleware.py(23)test_ddt_middleware_normal()\r\n    -> response = client.get('/api/', HTTP_ACCEPT='text/html')\r\n    [26]   …/Vcs/django/django/test/client.py(531)get()\r\n    -> **extra)\r\n    [27]   …/Vcs/django/django/test/client.py(333)get()\r\n    -> return self.generic('GET', path, secure=secure, **r)\r\n    [28]   …/Vcs/django/django/test/client.py(409)generic()\r\n    -> return self.request(**r)\r\n    [29]   …/Vcs/django/django/test/client.py(478)request()\r\n    -> response = self.handler(environ)\r\n    [30]   …/Vcs/django/django/utils/six.py(686)reraise()\r\n    -> raise value\r\n    [31]   …/Vcs/django/django/core/handlers/exception.py(39)inner()\r\n    -> response = get_response(request)\r\n    [32]   …/app/middleware.py(37)__call__()\r\n    -> if not (request.user and\r\n    [33]   …/Vcs/django/django/utils/functional.py(234)inner()\r\n    -> self._setup()\r\n    [34]   …/Vcs/django/django/utils/functional.py(380)_setup()\r\n    -> self._wrapped = self._setupfunc()\r\n    [35]   …/Vcs/django/django/contrib/auth/middleware.py(24)<lambda>()\r\n    -> request.user = SimpleLazyObject(lambda: get_user(request))\r\n    [36]   …/Vcs/django/django/contrib/auth/middleware.py(12)get_user()\r\n    -> request._cached_user = auth.get_user(request)\r\n    [37] > …/Vcs/django/django/contrib/auth/__init__.py(187)get_user()\r\n    -> user = backend.get_user(user_id)\r\n\r\n\r\nThe pytest test looks like this:\r\n\r\n```python\r\ndef test_foobar(db, client, some_user, some_group):\r\n    some_user.groups.add(some_group)\r\n    some_user.save()\r\n    client.force_login(some_user)\r\n\r\n```\r\n\r\nSetting a password and using `login` works:\r\n\r\n```python\r\ndef test_foobar(db, client, some_user, some_group):\r\n    some_user.groups.add(some_group)\r\n    some_user.set_password('password')\r\n    some_user.save()\r\n    assert client.login(username=some_user.username,\r\n                        password='password')\r\n```\r\n\r\n\r\nAccording to the documentation the `get_user` method is required:\r\nhttps://docs.djangoproject.com/en/1.10/topics/auth/customizing/#writing-an-authentication-backend.\r\n"},"comment":{"url":"https://api.github.com/repos/dfunckt/django-rules/issues/comments/262530793","html_url":"https://github.com/dfunckt/django-rules/issues/46#issuecomment-262530793","issue_url":"https://api.github.com/repos/dfunckt/django-rules/issues/46","id":262530793,"user":{"login":"orf","id":1027207,"avatar_url":"https://avatars.githubusercontent.com/u/1027207?v=3","gravatar_id":"","url":"https://api.github.com/users/orf","html_url":"https://github.com/orf","followers_url":"https://api.github.com/users/orf/followers","following_url":"https://api.github.com/users/orf/following{/other_user}","gists_url":"https://api.github.com/users/orf/gists{/gist_id}","starred_url":"https://api.github.com/users/orf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orf/subscriptions","organizations_url":"https://api.github.com/users/orf/orgs","repos_url":"https://api.github.com/users/orf/repos","events_url":"https://api.github.com/users/orf/events{/privacy}","received_events_url":"https://api.github.com/users/orf/received_events","type":"User","site_admin":false},"created_at":"2016-11-23T14:42:57Z","updated_at":"2016-11-23T14:42:57Z","body":"I think this should be added to the documentation, this is quite confusing."}}
{"actor":{"display_login":"orf"}}