﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19954	Storing of Binary fields leads to Exceptions	marcel.ryser.ch@…	nobody	"I am using a BinaryField on a table to store a binary value

Class for this BinaryField:
{{{
class BinaryField(models.TextField):
    def get_prep_value(self, value):
        return value;
}}}

This worked with 1.4 release pretty good. With 1.5 i got this exception

{{{
  File ""C:\Program Files\Python27\lib\site-packages\django\core\handlers\base.py"", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File ""C:\dev\workspace\myproject\Project\src\package\adminviews.py"", line 16, in changevalue
    movie.save()
  File ""C:\Program Files\Python27\lib\site-packages\django\db\models\base.py"", line 546, in save
    force_update=force_update, update_fields=update_fields)
  File ""C:\Program Files\Python27\lib\site-packages\django\db\models\base.py"", line 626, in save_base
    rows = manager.using(using).filter(pk=pk_val)._update(values)
  File ""C:\Program Files\Python27\lib\site-packages\django\db\models\query.py"", line 603, in _update
    return query.get_compiler(self.db).execute_sql(None)
  File ""C:\Program Files\Python27\lib\site-packages\django\db\models\sql\compiler.py"", line 1014, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File ""C:\Program Files\Python27\lib\site-packages\django\db\models\sql\compiler.py"", line 840, in execute_sql
    cursor.execute(sql, params)
  File ""C:\Program Files\Python27\lib\site-packages\django\db\backends\util.py"", line 45, in execute
    sql = self.db.ops.last_executed_query(self.cursor, sql, params)
  File ""C:\Program Files\Python27\lib\site-packages\django\db\backends\mysql\base.py"", line 243, in last_executed_query
    return cursor._last_executed.decode('utf-8')
  File ""C:\Program Files\Python27\lib\encodings\utf_8.py"", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 708: invalid start byte
}}}

This is right, one cannot decode a binary value to utf8 characters. So I saw Ticket #6416 which describes pretty good my problem. I patched the mysql adapter with the code from #6416 and now it works. I don't know exactly on which level this should be fixed, but it is also a problem when it comes to logging of this sql query with a binary field in it, the encoding to bas64 (from code #6416) solves this problem here.
"	Bug	closed	Database layer (models, ORM)	1.5	Normal	fixed			Accepted	1	0	0	1	0	0
