diff --git a/frappe/__init__.py b/frappe/__init__.py index 497e47d890..f055f4d940 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -7,8 +7,7 @@ globals attached to frappe module from __future__ import unicode_literals from werkzeug.local import Local, release_local -import os, importlib, inspect -import json +import os, importlib, inspect, logging, json # public from frappe.__version__ import __version__ @@ -639,3 +638,14 @@ def get_print_format(doctype, name, print_format=None, style=None, as_pdf=False) return html else: return html + +logging_setup_complete = False +def get_logger(module=None): + from frappe.setup_logging import setup_logging + global logging_setup_complete + + if not logging_setup_complete: + setup_logging() + logging_setup_complete = True + + return logging.getLogger(module or "frappe") diff --git a/frappe/app.py b/frappe/app.py index c06cd44df7..338f9d3805 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -20,15 +20,13 @@ import frappe.utils.response import frappe.website.render from frappe.utils import get_site_name from frappe.middlewares import StaticDataMiddleware -from frappe.setup_logging import setup_logging local_manager = LocalManager([frappe.local]) _site = None _sites_path = os.environ.get("SITES_PATH", ".") -setup_logging() -logger = logging.getLogger(__name__) +logger = frappe.get_logger() @Request.application def application(request): diff --git a/frappe/core/doctype/notification_count/notification_count.py b/frappe/core/doctype/notification_count/notification_count.py index d58beb5029..1cb7253d3e 100644 --- a/frappe/core/doctype/notification_count/notification_count.py +++ b/frappe/core/doctype/notification_count/notification_count.py @@ -5,8 +5,11 @@ from __future__ import unicode_literals import frappe +import MySQLdb from frappe.model.document import Document +logger = frappe.get_logger() + class NotificationCount(Document): pass @@ -34,18 +37,34 @@ def get_notifications(): result = frappe.get_list(d, fields=["count(*)"], filters=[[d, key, "=", condition[key]]], as_list=True)[0][0] - frappe.get_doc({"doctype":"Notification Count", "for_doctype":d, - "open_count":result}).insert(ignore_permissions=True) - open_count_doctype[d] = result + try: + frappe.get_doc({"doctype":"Notification Count", "for_doctype":d, + "open_count":result}).insert(ignore_permissions=True) + + except MySQLdb.OperationalError, e: + if e.args[0] != 1213: + raise + + logger.error("Deadlock") + for m in config.for_module: if m in notification_count: open_count_module[m] = notification_count[m] else: open_count_module[m] = frappe.get_attr(config.for_module[m])() - frappe.get_doc({"doctype":"Notification Count", "for_doctype":m, - "open_count":open_count_module[m]}).insert(ignore_permissions=True) + + try: + frappe.get_doc({"doctype":"Notification Count", "for_doctype":m, + "open_count":open_count_module[m]}).insert(ignore_permissions=True) + + except MySQLdb.OperationalError, e: + if e.args[0] != 1213: + raise + + logger.error("Deadlock") + return { "open_count_doctype": open_count_doctype, diff --git a/frappe/public/css/font/noto-sans.woff b/frappe/public/css/font/noto-sans.woff deleted file mode 100644 index ff45f43258..0000000000 Binary files a/frappe/public/css/font/noto-sans.woff and /dev/null differ diff --git a/frappe/setup_logging.py b/frappe/setup_logging.py index 894f7186c9..f7fbc09d21 100644 --- a/frappe/setup_logging.py +++ b/frappe/setup_logging.py @@ -35,7 +35,7 @@ def setup_logging(): } }, "loggers": { - "frappe.app": { + "frappe": { "level": "INFO", "propagate": False, "filters": ["context_filter"], diff --git a/frappe/utils/email_lib/email_body.py b/frappe/utils/email_lib/email_body.py index d27c5db990..1073283411 100644 --- a/frappe/utils/email_lib/email_body.py +++ b/frappe/utils/email_lib/email_body.py @@ -31,7 +31,7 @@ class EMail: Also provides a clean way to add binary `FileData` attachments Also sets all messages as multipart/alternative for cleaner reading in text-only clients """ - def __init__(self, sender='', recipients=[], subject='', alternative=0, reply_to=None): + def __init__(self, sender='', recipients=(), subject='', alternative=0, reply_to=None): from email.mime.multipart import MIMEMultipart from email import Charset Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8')