Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete of test-only object cause DatabaseError #116

Closed
JanBednarik opened this issue Apr 18, 2013 · 6 comments
Closed

Delete of test-only object cause DatabaseError #116

JanBednarik opened this issue Apr 18, 2013 · 6 comments

Comments

@JanBednarik
Copy link

I have myapp (which is in settings.INSTALLED_APPS):

myapp/
    __init__.py
    models.py
    tests.py

tests.py:

from django.db import models
from django.test import TestCase

class FooModel(models.Model):
    bar = models.CharField(null=True, blank=True)

class FooModelTest(TestCase):
    def test_foo(self):
        foo = FooModel.objects.create()
        foo.delete()

Because django-nose has bugged support for test-only models (issue #15) and it's still not possible to run tests as "./manage.py test", I run tests with workaround for issue #15 specifying all apps names:

./manage.py test myapp otherapp ...

And I get error caused by attempt to delete object which is instance of test-only model. Traceback:

Traceback (most recent call last):
  File "/Users/honza/dev/tmp/myapp/tests.py", line 10, in test_foo
    foo.delete()
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/models/base.py", line 575, in delete
    collector.collect([self])
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/models/deletion.py", line 175, in collect
    if not sub_objs:
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/models/query.py", line 130, in __nonzero__
    iter(self).next()
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/models/query.py", line 118, in _result_iter
    self._fill_cache()
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/models/query.py", line 892, in _fill_cache
    self._result_cache.append(self._iter.next())
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/models/query.py", line 291, in iterator
    for row in compiler.results_iter():
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 763, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
    cursor.execute(sql, params)
  File "/Users/honza/dev/envs/emdev/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 344, in execute
    return Database.Cursor.execute(self, query, params)
DatabaseError: no such table: nose_c

Packages:

Django==1.4.2
nose==1.3.0
django-nose==1.1
@fabiosantoscode
Copy link
Contributor

I can't access the internet to reproduce your environment right now, but I have failed to reproduce this on

python 2.7,

python 3.3,

django 1.5,

nose 1.2.1, and

django_nose 1.1 on jonashaag's fork which works on py3

I'll try later with your exact environment. perhaps you could try upgrading django or django_nose?

@JanBednarik
Copy link
Author

I tried it with fresh environment with:

python 2.7.3
Django==1.4.2
nose==1.3.0
django-nose==1.1

And I can't reproduce it again. I'm a little confused.

I can still reproduce it in an environment of a my huge Django project where are tens of packages. I probably used that environment by mistake when I was writing this issue. Sorry for confusion.

However it happens only when I use django-nose test runner. With Django's default test runner it works fine in the same environment. So I assumed it's django-nose issue. But now it looks like it's probably related to another package too. I'll investigate it further.

@JanBednarik
Copy link
Author

I can't find out what causes this problem and how to properly reproduce it in clean environment. However I found more info about the same error here: #15 (comment) Hack described there works for me so I'm closing this issue until I'll know whats the cause for this error.

@fabiosantoscode
Copy link
Contributor

I thought my #111 pulll request fixed #15. Have you tried it out?

@JanBednarik
Copy link
Author

Yes I tried. Patch #111 works fine for building test-only models database, but does not affect this issue.

@cansin
Copy link

cansin commented Feb 22, 2014

I am still having django.db.utils.OperationalError: no such table: error while calling the .objects.create() method (rather than delete) with below env:

Python 3.3.3
Django (1.6.1)
django-nose (1.2)
nose (1.3.0) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants