Forums

AttributeError: 'SessionStore' object has no attribute '_session_cache' followed by mysql.connector.errors.OperationalError: MySQL Connection not available.

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/contrib/sessions/backends/base.py", line 168, in _get_session
    return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/__init__.py", line 134, in _cursor
    return self.create_cursor()
  File "/usr/local/lib/python3.4/dist-packages/mysql/connector/django/base.py", line 537, in create_cursor
    cursor = self.connection.cursor()
  File "/usr/local/lib/python3.4/dist-packages/mysql/connector/connection.py", line 1328, in cursor
    raise errors.OperationalError("MySQL Connection not available.")
mysql.connector.errors.OperationalError: MySQL Connection not available.

I'm using Python 3.4 with Django 1.6 with mysql-connector-python 1.2.2.

I consistently get the above errors whenever I refresh the page after being idle for a while. I have tried setting CONN_MAX_AGE to 299/None/not setting it at all which defaults to 0, and it still occurs. When I return to the home page there are no errors but then if I go back to the original page I get this other error:

File "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/where.py" in process
  365.                     connection=connection, prepared=True)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/__init__.py" in get_db_prep_lookup
  407.                                            prepared=prepared)]
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  912.         return connection.ops.value_to_db_datetime(value)
File "/usr/local/lib/python3.4/dist-packages/mysql/connector/django/base.py" in value_to_db_datetime
  392.         return self.connection.connection.converter._datetime_to_mysql(value)

Exception Type: AttributeError at /user/log_in
Exception Value: 'NoneType' object has no attribute 'converter'

My website has the home page which doesn't do anything with the Django request object, and every other page requires a login. My steps to reproduce this is

  1. Log in to website
  2. Go to any page that requires me to be logged in
  3. Do nothing on the website for around half an hour (could be shorter but I always leave to do something else)
  4. Refresh the page and get the above 2 errors
  5. Go to the home page which loads fine
  6. Go to any page that requires me to be logged in and get the third error

That is perplexing.

Clutching at straws a little, try lowering that CONN_MAX_AGE, to 250 say, just in case the 299/300 was a bit too close to the limit.

Another clue is here -- http://bugs.mysql.com/bug.php?id=67649 -- could that be happening? i would be surprised, given that you're using django...

I changed it to 250 and repeated the steps and got the same results. Then I tried it at 50 and this time I logged in and refreshed the dashboard every minute. After 11 minutes of that I got the first 2 errors once but it went away after I refreshed again.

Turns out the steps are even simpler:

  1. Reload the entire site through the PA settings
  2. Go to the login page
  3. Sit there for half an hour
  4. Refresh the page and get the PA "something has gone wrong" page
  5. Refresh it again and get the converter error

The converter error happens on if request.user.is_authenticated (): which is the first line in the view that does anything with the database. The only line above that is an empty dictionary declaration.

Maybe the bug you mentioned could be happening but I don't know if I would be causing that. I'm doing everything through Django normally and nothing through its manual database stuff.

I've bumped the server's global max_connections variable -- it didn't look like we were anywhere near the limit, but right now isn't our most busy time of day. Can you give it another try?

It's still happening. I'm going to trim down the website to see if content could have anything to do with it.

Edit

I removed all urls except for the index, login, and logout pages from the urlconf. It happens still. I found this line in the server log:

2014-08-23 16:36:21 Sat Aug 23 16:36:21 2014 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /user/log_in (ip 10.138.64.83) !!!

OK, still clutching at straws, but you could try installing a different mysql connection library? or temporarily switching to sqlite?

I switched to sqlite. It appears to have solved the problem.

OK, well I'm glad you managed to get it working. We'll see if we can track down a root cause for the mysql issues when we're all back in the office on Tuesday, and keep you posted...

Try using python 3.3 instead. Are you using a special feature that python 3.3 does not have?

From the website of Django:

Python 3.4 is not supported, but support will be added in Django 1.7.

Cheers

+1 to that.