Commit 8fb46cf9 authored by Nicolas Chauvat's avatar Nicolas Chauvat

merge 3.30 into 3.31

--HG--
branch : 3.31
Pipeline #68145 passed with stages
in 22 minutes and 29 seconds
......@@ -686,5 +686,6 @@ a20956da474443f84cee8f41e8d7e88683a4c124 3.28.5
7ddad2aa6426aa73c09cc8232ecbe0f11bfd5d9c 3.29.2
f5768f140cde2e522be7c14ec180e87865890743 3.29.3
2052a708e92d598936cc84b8eb1030281283d2fc 3.29.4
df3bf737b60e189bfa8e1e365157e8c36bc50ba3 3.29.5
bedf6cb540ca4dd0b099ce3c6b00e1202d48168a 3.30.0
f0007241c4773160b6c2b93a0b56a9617a74389c 3.31.1
......@@ -30,6 +30,10 @@ SUBSCRIBERS = {
}
def debug_channel_has_subscribers(channel):
return len(SUBSCRIBERS.get(channel, [])) > 0
def subscribe_to_debug_channel(channel, subscriber):
"""
Allow to subscribe a callable to one of the debug channels.
......
......@@ -36,7 +36,7 @@ from cubicweb import ValidationError, Unauthorized, UnknownEid, QueryError
from cubicweb.rqlrewrite import RQLRelationRewriter
from cubicweb import Binary, server
from cubicweb.rset import ResultSet
from cubicweb.debug import emit_to_debug_channel
from cubicweb.debug import debug_channel_has_subscribers, emit_to_debug_channel
from cubicweb.utils import RepeatList
from cubicweb.misc.source_highlight import highlight_terminal
......@@ -512,6 +512,8 @@ class QuerierHelper(object):
always use substitute arguments in queries (i.e. avoid query such as
'Any X WHERE X eid 123'!)
"""
use_debug_channel = debug_channel_has_subscribers("rql")
if server.DEBUG & (server.DBG_RQL | server.DBG_SQL):
if server.DEBUG & (server.DBG_MORE | server.DBG_SQL):
print('*'*80)
......@@ -550,14 +552,15 @@ class QuerierHelper(object):
plan.rql_query_tracing_token = str(uuid.uuid4())
prepare_plan(plan, self.schema, self._repo.vreg.rqlhelper)
query_debug_informations = {
"rql": rql,
"rql_query_tracing_token": plan.rql_query_tracing_token,
"args": args,
# remove the last part of the stack which is: this line
"callstack": "".join(traceback.format_stack()[:-1]),
"description": "",
}
if use_debug_channel:
query_debug_informations = {
"rql": rql,
"rql_query_tracing_token": plan.rql_query_tracing_token,
"args": args,
# remove the last part of the stack which is: this line
"callstack": "".join(traceback.format_stack()[:-1]),
"description": "",
}
start = time.time()
# execute the plan
......@@ -576,8 +579,9 @@ class QuerierHelper(object):
cnx.commit_state = 'uncommitable'
raise
query_debug_informations["time"] = ((time.time() - start) * 1000)
query_debug_informations["result"] = results
if use_debug_channel:
query_debug_informations["time"] = (time.time() - start) * 1000
query_debug_informations["result"] = results
# build a description for the results if necessary
descr = ()
......@@ -605,9 +609,11 @@ class QuerierHelper(object):
descr = _build_descr(cnx, results, basedescr, todetermine)
# FIXME: get number of affected entities / relations on non
# selection queries ?
query_debug_informations["description"] = descr
if use_debug_channel:
query_debug_informations["description"] = descr
emit_to_debug_channel("rql", query_debug_informations)
if use_debug_channel:
emit_to_debug_channel("rql", query_debug_informations)
# return a result set object
return ResultSet(results, rql, args, descr, variables)
......
......@@ -42,7 +42,7 @@ from yams.schema import role_name
from cubicweb import (UnknownEid, AuthenticationError, ValidationError, Binary,
UniqueTogetherError, UndoTransactionException, ViolatedConstraint)
from cubicweb import transaction as tx, server, neg_role, _
from cubicweb.debug import emit_to_debug_channel
from cubicweb.debug import debug_channel_has_subscribers, emit_to_debug_channel
from cubicweb.schema import VIRTUAL_RTYPES
from cubicweb.cwconfig import CubicWebNoAppConfiguration
from cubicweb.server import hook
......@@ -683,14 +683,15 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
"""Execute a query.
it's a function just so that it shows up in profiling
"""
query_debug_informations = {
"sql": query,
"args": args,
"rollback": False,
"callstack": "".join(traceback.format_stack()[:-1]),
"rql_query_tracing_token": rql_query_tracing_token,
}
use_debug_channel = debug_channel_has_subscribers("sql")
if use_debug_channel:
query_debug_informations = {
"sql": query,
"args": args,
"rollback": False,
"callstack": "".join(traceback.format_stack()[:-1]),
"rql_query_tracing_token": rql_query_tracing_token,
}
start = time.time()
......@@ -709,7 +710,8 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
if rollback:
try:
cnx.cnxset.rollback()
query_debug_informations["rollback"] = True
if use_debug_channel:
query_debug_informations["rollback"] = True
if self.repo.config.mode != 'test':
self.debug('transaction has been rolled back')
except Exception as rollback_exc:
......@@ -757,8 +759,9 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
),)
raise
finally:
query_debug_informations["time"] = (time.time() - start) * 1000
emit_to_debug_channel("sql", query_debug_informations)
if use_debug_channel:
query_debug_informations["time"] = (time.time() - start) * 1000
emit_to_debug_channel("sql", query_debug_informations)
return cursor
def doexecmany(self, cnx, query, args):
......
......@@ -16,6 +16,12 @@ cubicweb (3.30.0-1) unstable; urgency=medium
-- Simon Chabot <simon.chabot@logilab.fr> Tue, 16 Mar 2021 16:28:48 +0100
cubicweb (3.29.5-1) unstable; urgency=medium
* New bugfix release
-- Aurélien Lubert <aurelien.lubert@logilab.fr> Fri, 09 Jul 2021 11:20:42 +0200
cubicweb (3.29.4-1) unstable; urgency=medium
* New bugfix release
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment