{"action":"created","issue":{"url":"https://api.github.com/repos/django-nose/django-nose/issues/119","labels_url":"https://api.github.com/repos/django-nose/django-nose/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/django-nose/django-nose/issues/119/comments","events_url":"https://api.github.com/repos/django-nose/django-nose/issues/119/events","html_url":"https://github.com/django-nose/django-nose/issues/119","id":13802936,"number":119,"title":"REUSE_DB for tests fails when using django-guardian's ANONYMOUS_USER_ID as -1","user":{"login":"anthonyfinch","id":617631,"avatar_url":"https://avatars.githubusercontent.com/u/617631?v=3","gravatar_id":"","url":"https://api.github.com/users/anthonyfinch","html_url":"https://github.com/anthonyfinch","followers_url":"https://api.github.com/users/anthonyfinch/followers","following_url":"https://api.github.com/users/anthonyfinch/following{/other_user}","gists_url":"https://api.github.com/users/anthonyfinch/gists{/gist_id}","starred_url":"https://api.github.com/users/anthonyfinch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthonyfinch/subscriptions","organizations_url":"https://api.github.com/users/anthonyfinch/orgs","repos_url":"https://api.github.com/users/anthonyfinch/repos","events_url":"https://api.github.com/users/anthonyfinch/events{/privacy}","received_events_url":"https://api.github.com/users/anthonyfinch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2013-04-30T11:52:37Z","updated_at":"2015-06-12T07:51:49Z","closed_at":null,"body":"Was unsure whether this one really belonged here or with django-guardian, so apologies in advance if this is inappropriate.\r\n\r\nBriefly, when using django-guardian (https://github.com/lukaszb/django-guardian) with the ANONYMOUS_USER_ID set to -1, tests work perfectly the first time round. However, when using REUSE_DB, on a second pass, django_nose cannot reset the database successfully.\r\n\r\nUsing the ANONYMOUS_USER_ID of -1 as suggested in the documentation for django-guardian (http://django-guardian.readthedocs.org/en/latest/configuration.html), reusing the database to run tests fails when resetting the database to it's 'clean' state. The error given is as follows:\r\n\r\n`django.db.utils.DatabaseError: setval: value -1 is out of bounds for sequence \"auth_user_id_seq\" (1..9223372036854775807)`\r\n\r\nExamining the reset statements, the one causing the error is:\r\n`SELECT setval(pg_get_serial_sequence('\"auth_user\"','id'), coalesce(max(\"id\"), 1), max(\"id\") IS NOT null) FROM \"auth_user\";`\r\n\r\nThe User object with id of -1 is created automatically by a signal hooked to post_syncdb in django_guardian's management/__init__.py.\r\n\r\nUsing: Django 1.4.3, django-guardian 1.0.4, postgres 9.1 with postgis 1.5.\r\nDjango engine: `django.contrib.gis.db.backends.postgis`\r\n\r\nThe full stack trace:\r\n```python\r\nTraceback (most recent call last):\r\n  File \"./manage.py\", line 9, in <module>\r\n    execute_from_command_line(sys.argv)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 443, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 382, in execute\r\n    self.fetch_command(subcommand).run_from_argv(self.argv)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django/core/management/commands/test.py\", line 49, in run_from_argv\r\n    super(Command, self).run_from_argv(argv)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django/core/management/base.py\", line 196, in run_from_argv\r\n    self.execute(*args, **options.__dict__)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django/core/management/base.py\", line 232, in execute\r\n    output = self.handle(*args, **options)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/south/management/commands/test.py\", line 8, in handle\r\n    super(Command, self).handle(*args, **kwargs)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django/core/management/commands/test.py\", line 72, in handle\r\n    failures = test_runner.run_tests(test_labels)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django_nose/runner.py\", line 155, in run_tests\r\n    result = self.run_suite(nose_argv)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django_nose/runner.py\", line 117, in run_suite\r\n    addplugins=plugins_to_add)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/nose/core.py\", line 118, in __init__\r\n    **extra_args)\r\n  File \"/usr/lib/python2.7/unittest/main.py\", line 95, in __init__\r\n    self.runTests()\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/nose/core.py\", line 197, in runTests\r\n    result = self.testRunner.run(self.test)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/nose/core.py\", line 50, in run\r\n    wrapper = self.config.plugins.prepareTest(test)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/nose/plugins/manager.py\", line 99, in __call__\r\n    return self.call(*arg, **kw)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/nose/plugins/manager.py\", line 167, in simple\r\n    result = meth(*arg, **kw)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django_nose/plugin.py\", line 78, in prepareTest\r\n    self.old_names = self.runner.setup_databases()\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django_nose/runner.py\", line 308, in setup_databases\r\n    cursor.execute(reset_statement)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django/db/backends/util.py\", line 40, in execute\r\n    return self.cursor.execute(sql, params)\r\n  File \"/home/tony/.virtualenvs/trialreach/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py\", line 52, in execute\r\n    return self.cursor.execute(query, args)\r\ndjango.db.utils.DatabaseError: setval: value -1 is out of bounds for sequence \"auth_user_id_seq\" (1..9223372036854775807)\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/django-nose/django-nose/issues/comments/111397637","html_url":"https://github.com/django-nose/django-nose/issues/119#issuecomment-111397637","issue_url":"https://api.github.com/repos/django-nose/django-nose/issues/119","id":111397637,"user":{"login":"Mactory","id":493594,"avatar_url":"https://avatars.githubusercontent.com/u/493594?v=3","gravatar_id":"","url":"https://api.github.com/users/Mactory","html_url":"https://github.com/Mactory","followers_url":"https://api.github.com/users/Mactory/followers","following_url":"https://api.github.com/users/Mactory/following{/other_user}","gists_url":"https://api.github.com/users/Mactory/gists{/gist_id}","starred_url":"https://api.github.com/users/Mactory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mactory/subscriptions","organizations_url":"https://api.github.com/users/Mactory/orgs","repos_url":"https://api.github.com/users/Mactory/repos","events_url":"https://api.github.com/users/Mactory/events{/privacy}","received_events_url":"https://api.github.com/users/Mactory/received_events","type":"User","site_admin":false},"created_at":"2015-06-12T07:51:49Z","updated_at":"2015-06-12T07:51:49Z","body":"I came across the same problem. Is there a solution for this yet?"}}