Git Product home page Git Product logo

Comments (6)

mtford90 avatar mtford90 commented on August 25, 2024 3

Not familiar with MySQL, only used postgres and sqlite which explains why I haven't run into this issue myself.

Did a bit of research and doesn't look like Django provides the ability to set charsets on the tables and will assume UTF-8. See here and here for stackoverflow threads where people are facing a similar issue with MySQL.

Looks like you can use the following for database default charsets:

ALTER DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci;

which should ensure that any tables created by Django take UTF from then on. And then if you want to retroactively fit the existing silk tables:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;

Hope this helps.

from django-silk.

mtford90 avatar mtford90 commented on August 25, 2024

Interesting, looks like some kind of encoding issue, see https://docs.djangoproject.com/en/dev/ref/unicode/, in particular the MySQL comments.

I can see from the page content that the charset is utf-8, is your MySQL database configured to support UTF char encodings?

Let me know, if this is the issue i'll add some defensive code to Silk to try and spot this kind of thing. Obviously this error is pretty unhelpful...

Cheers.

from django-silk.

mtford90 avatar mtford90 commented on August 25, 2024

In the meantime if you set the following in settings.py:

SILKY_MAX_REQUEST_BODY_SIZE = 0
SILKY_MAX_RESPONSE_BODY_SIZE = 0

then silk will stop saving the bodies down. As long as you have no UTF characters in the query params/headers etc the error should go away and you can use Silk minus body inspection

from django-silk.

makmanalp avatar makmanalp commented on August 25, 2024

That is a good question, you tell me! :) The encodings are set on a per-table basis.

MySQL says of the silk tables:

mysql> show create table silk_response\G
*************************** 1. row ***************************
       Table: silk_response
Create Table: CREATE TABLE `silk_response` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `request_id` int(11) NOT NULL,
  `status_code` int(11) NOT NULL,
  `raw_body` longtext NOT NULL,
  `body` longtext NOT NULL,
  `encoded_headers` longtext NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `request_id` (`request_id`),
  CONSTRAINT `request_id_refs_id_da922f86` FOREIGN KEY (`request_id`) REFERENCES `silk_request` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

mysql> show create table silk_request\G
*************************** 1. row ***************************
       Table: silk_request
Create Table: CREATE TABLE `silk_request` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `path` varchar(300) NOT NULL,
  `query_params` longtext NOT NULL,
  `raw_body` longtext NOT NULL,
  `body` longtext NOT NULL,
  `method` varchar(10) NOT NULL,
  `start_time` datetime NOT NULL,
  `view_name` varchar(300) NOT NULL,
  `end_time` datetime DEFAULT NULL,
  `time_taken` double DEFAULT NULL,
  `encoded_headers` longtext NOT NULL,
  `meta_time` double DEFAULT NULL,
  `meta_num_queries` int(11) DEFAULT NULL,
  `meta_time_spent_queries` double DEFAULT NULL,
  `num_sql_queries` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `silk_request_73e78684` (`path`),
  KEY `silk_request_b2ae6dce` (`view_name`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

So they're latin-1 by default, it seems.

Thanks for the workaround.

from django-silk.

mtford90 avatar mtford90 commented on August 25, 2024

Closing this as Django does not present any method in which to force table encodings so nothing can be done from the Silk side of things.

from django-silk.

medson avatar medson commented on August 25, 2024

Not familiar with MySQL, only used postgres and sqlite which explains why I haven't run into this issue myself.

Did a bit of research and doesn't look like Django provides the ability to set charsets on the tables and will assume UTF-8. See here and here for stackoverflow threads where people are facing a similar issue with MySQL.

Looks like you can use the following for database default charsets:

ALTER DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci;

which should ensure that any tables created by Django take UTF from then on. And then if you want to retroactively fit the existing silk tables:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;

Hope this helps.

Thanks, this works for me 😄

from django-silk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.