1

The issue that we are getting is : we have run manage.py makemigrations and manage.py migrate successfully, after which we start getting the below error:

 File "/usr/local/goibibo/python/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 110, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/goibibo/python/lib/python3.5/site-packages/MySQLdb/cursors.py", line 250, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/goibibo/python/lib/python3.5/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
    raise errorvalue
  File "/usr/local/goibibo/python/lib/python3.5/site-packages/MySQLdb/cursors.py", line 247, in execute
    res = self._query(query)
  File "/usr/local/goibibo/python/lib/python3.5/site-packages/MySQLdb/cursors.py", line 411, in _query
    rowcount = self._do_query(q)
  File "/usr/local/goibibo/python/lib/python3.5/site-packages/MySQLdb/cursors.py", line 374, in _do_query
    db.query(q)
  File "/usr/local/goibibo/python/lib/python3.5/site-packages/MySQLdb/connections.py", line 292, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (2027, 'Malformed packet')

This issue does not come every time we run makemigrations.
It comes randomly, but once it comes it just sticks and we have no clue on why this is happening. Can somebody assist us in fixing this and explain why this might be happening.

Packages Used in App:

adium-theme-ubuntu==0.3.4
appdirs==1.4.3
asn1crypto==0.22.0
backports-abc==0.5
blinker==1.4
boto3==1.4.4
botocore==1.5.35
certifi==2017.4.17
cffi==1.10.0
chardet==2.3.0
click==6.7
ConcurrentLogHandler==0.9.1
configobj==5.0.6
decorator==4.0.11
Django==1.10.4
djangorestframework==3.5.3
docutils==0.13.1
Flask==0.11.1
futures==3.1.1
gevent==1.2a1
greenlet==0.4.10
gyp==0.1
idna==2.5
itsdangerous==0.24
Jinja2==2.8
jmespath==0.9.2
jsonpatch==1.10
jsonpath==0.75
jsonpath-rw==1.4.0
jsonpointer==1.10
MarkupSafe==1.0
newrelic==2.82.0.62
oauthlib==1.0.3
packaging==16.8
Pillow==3.1.2
ply==3.10
prettytable==0.7.2
pyasn1==0.1.9
pycparser==2.17
pycurl==7.43.0
PyJWT==1.3.0
PyMySQL==0.7.9
PyOpenGL==3.0.2
pyparsing==2.2.0
Pyrex==0.9.8.5
pyserial==3.0.1
PySocks==1.6.5
python-dateutil==2.6.0
PyYAML==3.11
requests==2.14.2
s3transfer==0.1.10
singledispatch==3.4.0.3
six==1.10.0
SQLAlchemy==1.1.4
ssh-import-id==5.5
tornado==4.4.2
unity-lens-photos==1.0
urllib3==1.19.1
virtualenv==15.1.0
Werkzeug==0.12.1
abhinsit
  • 3,214
  • 4
  • 21
  • 26

2 Answers2

0

Resolved in mysql 5.6.17 by SET read_rnd_buffer_size=256000 for the session. Did not have to change my.ini (cfg).

Wilson Hauck
  • 2,094
  • 1
  • 11
  • 19
0

Same issue haunted my team for a while, and there's very little useful information about it on the web. We spent a lot of time troubleshooting the issue - and FINALLY found solution that solved it (at least - for our team)!

We found that Django sets "charset" option to "utf8" for database connections by default. During troubleshooting we used two separate database connection objects: one created for us by Django, and another - created manually using direct _mysql.connect() command. When we executed same exact query using both connection objects - the one created by Django resulted in "django.db.utils.OperationalError: (2027, 'Malformed packet')" (which is exactly what we were getting in our API), but the second connection (manual) - worked without any issues. Further comparison of the two connection objects (we actually had to use Python debugger "pdb" and set breakpoint within django.db.backends.mysql.base.py for that) - revealed that Django creates connection by passing "charset":"utf8", while manual _mysql connection - uses "latin1". As soon as we added "charset":"latin1" to DATABASES["default"]["OPTIONS"] within our settings.py - this error disappeared.

To summarize, solution (for us) was to explicitly set "charset":"latin1" within "OPTIONS" config section of DATABASES configuration - for every database alias. I can not say for sure that this will work for everyone who experiences this error - but it certainly works for us.

Val
  • 151
  • 1
  • 1
  • 4