Opened 8 years ago

Closed 8 years ago

#23536 closed Bug (invalid)

BinaryField on mysql gets retrieved as 'str', not as 'bytes'

Reported by: fbrau Owned by: nobody
Component: Uncategorized Version: 1.6
Severity: Normal Keywords: mysql BinaryField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a project that uses BinaryFields to pickle dynamic data.

Last week when migrating from sqlite to mysql
using MySQL-for-Python-3 the BinaryField now gets
retrieved as 'str'.

Reading the docs about BinaryField it says it is stored as 'bytes'.

I know mysql stores blobs
as text (right?) but in that case the problem is django's

In this particular case:
the attribute mymodel.myblob looked like: b'dadadadaa'
but type(mymodel.myblob) said it was a 'str'
(I'm bit outdated about latest python changes in strings, bytes

and unicode)

Anyways I had to bypass this different behaviour to act just
like the embedded sqlite driver. My 'solution' is not nice:

  • I had to reparse the string to make it a 'bytes':

    self._tags = eval('b"'+self.tags[2:-1]+'"')

  • And add proxy points to get and set the blob

The code is located at:

Change History (1)

comment:1 Changed 8 years ago by Claude Paroz

Resolution: invalid
Status: newclosed

This is a known limitation, documented in the third note here:

Now there's hope with a new fork of MySQLdb that we plan to promote (#23446),
If you make positive experiments with that driver, might be nice to comment on that ticket.

Note: See TracTickets for help on using tickets.
Back to Top