From c7f5c4afd2099f951dfe433ab18716062b2843db Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 26 Aug 2019 13:38:17 +0000 Subject: [FIX] sql_db: add flush() in savepoint() closes odoo/odoo#36060 Signed-off-by: Raphael Collet (rco) --- odoo/service/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'odoo/service') diff --git a/odoo/service/db.py b/odoo/service/db.py index 0cc86e4ee66..b3c90bd99a0 100644 --- a/odoo/service/db.py +++ b/odoo/service/db.py @@ -304,7 +304,7 @@ def restore_db(db, dump_file, copy=False): if odoo.tools.config['unaccent']: try: - with cr.savepoint(): + with cr.savepoint(flush=False): cr.execute("CREATE EXTENSION unaccent") except psycopg2.Error: pass -- cgit v1.2.3 From ae8770e7046f1160dc2a7e875e18f7d5d408435e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 29 Aug 2019 12:56:36 +0000 Subject: [FIX] core: gevent / longpolling logging * fix the gevent worker "logging" everything to stderr and ignoring the logging configuration: passing loggers to WSGIServer means it uses those loggers instead of writing directly to stderr * fix the gevent worker logging the wrong client address when behind a reverse proxy: it would log the client_address, immitate the behaviour of werkzeug which goes and gets whatever REMOTE_ADDR is set on the environment, that way it gets whatever update were performed by ProxyFix (if any) Fixes #32914 closes odoo/odoo#36233 Signed-off-by: Xavier Morel (xmo) --- odoo/service/server.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'odoo/service') diff --git a/odoo/service/server.py b/odoo/service/server.py index cab3f75fe85..490d204d166 100644 --- a/odoo/service/server.py +++ b/odoo/service/server.py @@ -554,9 +554,28 @@ class GeventServer(CommonServer): def start(self): import gevent try: - from gevent.pywsgi import WSGIServer + from gevent.pywsgi import WSGIServer, WSGIHandler except ImportError: - from gevent.wsgi import WSGIServer + from gevent.wsgi import WSGIServer, WSGIHandler + + class ProxyHandler(WSGIHandler): + """ When logging requests, try to get the client address from + the environment so we get proxyfix's modifications (if any). + + Derived from werzeug.serving.WSGIRequestHandler.log + / werzeug.serving.WSGIRequestHandler.address_string + """ + def format_request(self): + old_address = self.client_address + if getattr(self, 'environ', None): + self.client_address = self.environ['REMOTE_ADDR'] + elif not self.client_address: + self.client_address = '' + # other cases are handled inside WSGIHandler + try: + return super().format_request() + finally: + self.client_address = old_address set_limit_memory_hard() if os.name == 'posix': @@ -565,7 +584,12 @@ class GeventServer(CommonServer): signal.signal(signal.SIGUSR1, log_ormcache_stats) gevent.spawn(self.watchdog) - self.httpd = WSGIServer((self.interface, self.port), self.app) + self.httpd = WSGIServer( + (self.interface, self.port), self.app, + log=logging.getLogger('longpolling'), + error_log=logging.getLogger('longpolling'), + handler_class=ProxyHandler, + ) _logger.info('Evented Service (longpolling) running on %s:%s', self.interface, self.port) try: self.httpd.serve_forever() -- cgit v1.2.3 From 1a0a437855de3cf2b47a98862e8a577971ffb0a4 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 5 Sep 2019 14:05:30 +0000 Subject: [FIX] models.py: Don't commit after fetching a translation Purpose ======= When trying the translate a sql_contraint message after an integrity error we use the current cursor in a 'with', just to make a SELECT query. That way, the cursor is commited at the end of the with statement, trying to commit the inconsitent state of the cursor that was the reason of the integrity error. Just close the cursor, as we only fetch translations from the database. closes odoo/odoo#36458 Signed-off-by: Yannick Tivisse (yti) --- odoo/service/model.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'odoo/service') diff --git a/odoo/service/model.py b/odoo/service/model.py index 8f419e1c61d..9673b6f98c9 100644 --- a/odoo/service/model.py +++ b/odoo/service/model.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from contextlib import closing from functools import wraps import logging from psycopg2 import IntegrityError, OperationalError, errorcodes @@ -73,7 +74,7 @@ def check(f): # We open a *new* cursor here, one reason is that failed SQL # queries (as in IntegrityError) will invalidate the current one. - with odoo.sql_db.db_connect(dbname).cursor() as cr: + with closing(odoo.sql_db.db_connect(dbname).cursor()) as cr: if ttype == 'sql_constraint': res = translate_sql_constraint(cr, key=key, lang=lang) else: -- cgit v1.2.3