andreirk / django-hotclub

Automatically exported from code.google.com/p/django-hotclub
0 stars 0 forks source link

sqlite3 "unable to close due to.." error #72

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a clean, up-to-date Pinax and Django SVN, Ubuntu Hardy, Python 2.5.

{{{
$ cd django-hotclub/pinax
$ rm dev.db
$ ./manage.py syncdb
$ ./manage.py runserver
...
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py",
line 278, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py",
line 635, in __call__
    return self.application(environ, start_response)
  File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py",
line 246, in __call__
    signals.request_finished.send(sender=self.__class__)
  File "/usr/lib/python2.5/site-packages/django/dispatch/dispatcher.py",
line 148, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/lib/python2.5/site-packages/django/db/__init__.py", line 46,
in close_connection
    connection.close()
  File
"/usr/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line
158, in close
    BaseDatabaseWrapper.close(self)
  File "/usr/lib/python2.5/site-packages/django/db/backends/__init__.py",
line 51, in close
    self.connection.close()
OperationalError: Unable to close due to unfinalised statements
[26/Sep/2008 03:09:25] "GET /profiles/e/ HTTP/1.1" 500 1087
}}}

This type of error appears on several pages:

 * /profile/detail
 * /tweets
 * elsewhere maybe?

Does NOT happen with ./manage.py testserver!

Django docs indicate that this type of error is associated with permissions
problems on db file, however this doesn't seem to be the problem. Searching
I found fero reported possibly the same issue on 9/15 in #django.

Is anyone else experiencing this? It must be a platform dependent problem?

Original issue reported on code.google.com by ericd...@gmail.com on 26 Sep 2008 at 7:31

GoogleCodeExporter commented 9 years ago
triggered in both places by a call to FriendshipManager.are_friends

    def are_friends(self, user1, user2):
        if self.filter(from_user=user1, to_user=user2).count() > 0:
            return True
        if self.filter(from_user=user2, to_user=user1).count() > 0:
            return True

looks like a subtle upstream bug with the db api?

Original comment by ericd...@gmail.com on 26 Sep 2008 at 8:33

Attachments:

GoogleCodeExporter commented 9 years ago
hmm I tried rewriting the above function as

    def are_friends(self, user1, user2):
        if self.filter((Q(from_user=user1) & Q(to_user=user2))
                     | (Q(from_user=user2) & Q(to_user=user1))
        ).count() > 0:
            return True
        return False

but still get the same error. 

Original comment by ericd...@gmail.com on 26 Sep 2008 at 9:04

GoogleCodeExporter commented 9 years ago
Take a look at this ticket: http://code.djangoproject.com/ticket/882
See if his solution works and post back ericdrex.

Original comment by gregoryj...@gmail.com on 26 Sep 2008 at 9:07

GoogleCodeExporter commented 9 years ago
I had tried putting a self.connection.cursor().close() right before the last 
line of
the trace  in db/backends/__init__.py

I should mention that commenting either of the two tests in are_friends makes 
the
error go away.  I tried putting 

  from django.db import connection
  connection.cursor().close()

between the two tests, but this seems wrong and doesn't work anyway. What do 
you suggest?

Original comment by ericd...@gmail.com on 26 Sep 2008 at 9:23

GoogleCodeExporter commented 9 years ago
django-admin.py sqlclear with SQLite

Original comment by gregoryj...@gmail.com on 26 Sep 2008 at 9:25

GoogleCodeExporter commented 9 years ago
Ah, I see why the in-memory "testserver" database isn't affected:
http://code.djangoproject.com/browser/django/trunk/django/db/backends/sqlite3/ba
se.py#L154

Commenting the close line there certainly fixes it, but I'd imagine there may be
consequences for not closing your connection

Original comment by ericd...@gmail.com on 26 Sep 2008 at 9:34

GoogleCodeExporter commented 9 years ago
well, i give up for now. maybe there is enough info here to file an upstream bug
report, provided it's reproducible by someone?

Original comment by ericd...@gmail.com on 26 Sep 2008 at 9:52

GoogleCodeExporter commented 9 years ago
gregory: I'm not sure what you are suggesting. That ticket is very old. I think 
maybe
cursor.close needs to be called somewhere, but not sure where (since I tried at 
the
last possible moment)

Original comment by ericd...@gmail.com on 26 Sep 2008 at 7:52

GoogleCodeExporter commented 9 years ago
ericdrex, i'm simply asking you to try it.  I don't think anyone else has had 
issues with sqlite including myself.

Original comment by gregoryj...@gmail.com on 26 Sep 2008 at 7:56

GoogleCodeExporter commented 9 years ago
try what?

Original comment by ericd...@gmail.com on 26 Sep 2008 at 9:34

GoogleCodeExporter commented 9 years ago
Somehow I fixed this, I think by 
  find -type f -name "*.py[co]" -delete

Since it's a ghost bug, can somebody mark it a closed/invalid?

Original comment by ericd...@gmail.com on 27 Sep 2008 at 4:45

GoogleCodeExporter commented 9 years ago

Original comment by gregoryj...@gmail.com on 27 Sep 2008 at 10:13

GoogleCodeExporter commented 9 years ago
this behavior cropped up again when I moved (relocated) my django and 
django-hotclub
directories, and was fixed by running 
  find -type f -name "*.py[co]" -delete
on both directories, so this may be triggered by relocating one of those 
directories,
just in case anyone else encounters this.

Original comment by ericd...@gmail.com on 28 Sep 2008 at 3:30