Projet

Général

Profil

0001-tenant_command-convert-exception-to-UTF-8-30559.patch

Benjamin Dauvergne, 09 juillet 2019 17:32

Télécharger (2,28 ko)

Voir les différences:

Subject: [PATCH] tenant_command: convert exception to UTF-8 (#30559)

 .../management/commands/tenant_command.py     | 27 +++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
hobo/multitenant/management/commands/tenant_command.py
9 9
import sys
10 10

  
11 11
import django
12
from django.utils import six
13
from django.utils.encoding import force_text, force_bytes
12 14
from django.conf import settings
13 15
from django.core.exceptions import ImproperlyConfigured
14 16
from django.core.management.base import (BaseCommand, CommandError,
15
        SystemCheckError, handle_default_options)
17
                                         SystemCheckError,
18
                                         handle_default_options)
16 19
from django.core.management import call_command, get_commands, load_command_class
17 20
from django.db import connection, connections
18 21

  
19 22
from hobo.multitenant.management.commands import InteractiveTenantOption
20 23
from hobo.multitenant.middleware import TenantMiddleware
21 24

  
25

  
26
def exception_to_text(e):
27
    try:
28
        return six.text_type(e)
29
    except Exception:
30
        pass
31

  
32
    try:
33
        return force_text(str(e), errors='ignore')
34
    except Exception:
35
        pass
36

  
37
    try:
38
        return force_text(repr(e), errors='ignore')
39
    except Exception:
40
        pass
41

  
42
    return six.text_type('Unrepresentable exception %s' % e.__class__.__name__)
43

  
44

  
22 45
def run_command_from_argv(command, argv):
23 46
    # copied/adapted from Django run_from_argv
24 47
    command._called_from_command_line = True
......
44 67
            command.stderr.write(str(e), lambda x: x)
45 68
        else:
46 69
            command.stderr.write('%s: %s: %s' % (
47
                connection.get_tenant(), e.__class__.__name__, e))
70
                connection.get_tenant(), e.__class__.__name__, force_bytes(exception_to_text(e))))
48 71
        return e
49 72
    finally:
50 73
        try:
51
-