I have a Django (v2.2.23) application connected to a MySQL (v5.7) database. 
Every now and then, for a few minutes at a time, all my DB queries start to 
fail with one of the following errors: "Unknown MySQL Error" (error code 
2000), "InterfaceError", or "Malformed Packet" (error code 2027). The 
errors resolve themselves on their own after a few minutes, but then they 
pop up again a some time later (on average, every few hours). These errors 
happen seemingly at random and I haven't found any reliable way to 
reproduce them till now. There is nothing wrong with the code as far as I 
can see because when the queries do execute, they work as expected and give 
the correct results.

I have already made several attempts to fix the issue to no avail, 
including :-

   - Following all the steps given in this article 
   <https://chrissardegna.com/blog/debugging-an-obscure-django-problem/>
   - Increasing the value of connect_timeout and wait_timeout 
   
<https://stackoverflow.com/questions/14726789/how-can-i-change-the-default-mysql-connection-timeout-when-connecting-through-py>
   - Changing the charset used in the table in my DB (tried latin1 and utf8)
   - Upgrading the Python mysqlclient package 
   <https://pypi.org/project/mysqlclient/> to the latest version (2.0.3)

This error is occuring both on local and staging environments.

In order to debug this further, I create a custom exception handler and 
logged the error as well as the last 3 SQL queries 
<https://stackoverflow.com/questions/37616990/django-orm-how-can-i-see-last-executed-query-on-fly>
 executed 
(which I got using connection.queries[-3:]).

The result is given below:
'EXCEPTION': InterfaceError(0, ''), 'LAST_QUERIES': [{'sql': 'SET SESSION 
TRANSACTION ISOLATION LEVEL READ COMMITTED', 'time': '0.000'}, {'sql': 
None, 'time': '0.000'}] 

Notice that for the second query, the value of 'sql' is coming as None. Is 
Django trying to execute a null query? Could this be the cause of the 
strange, intermittent errors? Is this a bug inside Django or have I 
configured something incorrectly?

-- 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f81df377-2ddf-4b18-89e1-8991b028dea2n%40googlegroups.com.

Reply via email to