author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Mon, 25 Mar 2013 14:20:10 +0100 | |
changeset 8764 | c4f022a6c7dd |
parent 8763 | 0144b26e958d |
child 8765 | 9e9029ba2d4e |
permissions | -rw-r--r-- |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8096
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5226
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5701
41119f034735
[querier] fix rset description bug with some union queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""Repository users' and internal' sessions.""" |
0 | 19 |
__docformat__ = "restructuredtext en" |
20 |
||
21 |
import sys |
|
22 |
import threading |
|
23 |
from time import time |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
24 |
from uuid import uuid4 |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
25 |
from warnings import warn |
0 | 26 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2466
diff
changeset
|
27 |
from logilab.common.deprecation import deprecated |
7769
8af09eeee130
[session] take care of non-ascii characters in login and session id (closes: #1910849)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7757
diff
changeset
|
28 |
from logilab.common.textutils import unormalize |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8096
diff
changeset
|
29 |
from logilab.common.registry import objectify_predicate |
0 | 30 |
|
8626
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
31 |
from cubicweb import UnknownEid, QueryError, schema, server |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2788
diff
changeset
|
32 |
from cubicweb.req import RequestSessionBase |
8542
7e264ce34cd4
[session / querier] reorganize code to building result set descriptions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8538
diff
changeset
|
33 |
from cubicweb.utils import make_uid |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3198
diff
changeset
|
34 |
from cubicweb.rqlrewrite import RQLRewriter |
7573
c8f8762c986d
[repo, looping task] raise a custom exception when repository is shuting down, avoid looping task to be restarted in such case. Closes #1021276
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7526
diff
changeset
|
35 |
from cubicweb.server import ShuttingDown |
7119
8b29c4c2ffc6
[repository] fix crash in optimized [add|remove]_relation w/ inlined relation (broken by cw 3.10 refactoring)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7118
diff
changeset
|
36 |
from cubicweb.server.edition import EditedEntity |
0 | 37 |
|
7329
f2d52aa8bcdb
[session] new selectors according to session type (eg user or internal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7237
diff
changeset
|
38 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
39 |
NO_UNDO_TYPES = schema.SCHEMA_TYPES.copy() |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
40 |
NO_UNDO_TYPES.add('CWCache') |
5074
bc481dab93d4
[undo] consistent is/is_instance_of processing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5069
diff
changeset
|
41 |
# is / is_instance_of are usually added by sql hooks except when using |
bc481dab93d4
[undo] consistent is/is_instance_of processing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5069
diff
changeset
|
42 |
# dataimport.NoHookRQLObjectStore, and we don't want to record them |
bc481dab93d4
[undo] consistent is/is_instance_of processing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5069
diff
changeset
|
43 |
# anyway in the later case |
bc481dab93d4
[undo] consistent is/is_instance_of processing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5069
diff
changeset
|
44 |
NO_UNDO_TYPES.add('is') |
bc481dab93d4
[undo] consistent is/is_instance_of processing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5069
diff
changeset
|
45 |
NO_UNDO_TYPES.add('is_instance_of') |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
46 |
NO_UNDO_TYPES.add('cw_source') |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
47 |
# XXX rememberme,forgotpwd,apycot,vcsfile |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
48 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8096
diff
changeset
|
49 |
@objectify_predicate |
7329
f2d52aa8bcdb
[session] new selectors according to session type (eg user or internal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7237
diff
changeset
|
50 |
def is_user_session(cls, req, **kwargs): |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
51 |
"""return 1 when session is not internal. |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
52 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
53 |
This predicate can only be used repository side only. """ |
7330
584907154ce3
[session selector] missing not
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7329
diff
changeset
|
54 |
return not req.is_internal_session |
7329
f2d52aa8bcdb
[session] new selectors according to session type (eg user or internal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7237
diff
changeset
|
55 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8096
diff
changeset
|
56 |
@objectify_predicate |
7329
f2d52aa8bcdb
[session] new selectors according to session type (eg user or internal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7237
diff
changeset
|
57 |
def is_internal_session(cls, req, **kwargs): |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
58 |
"""return 1 when session is not internal. |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
59 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
60 |
This predicate can only be used repository side only. """ |
7329
f2d52aa8bcdb
[session] new selectors according to session type (eg user or internal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7237
diff
changeset
|
61 |
return req.is_internal_session |
f2d52aa8bcdb
[session] new selectors according to session type (eg user or internal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7237
diff
changeset
|
62 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8096
diff
changeset
|
63 |
@objectify_predicate |
7500
cb0f4da64e86
[repository] new hook selector according to configuration's repairing flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7451
diff
changeset
|
64 |
def repairing(cls, req, **kwargs): |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
65 |
"""return 1 when repository is running in repair mode""" |
7500
cb0f4da64e86
[repository] new hook selector according to configuration's repairing flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7451
diff
changeset
|
66 |
return req.vreg.config.repairing |
cb0f4da64e86
[repository] new hook selector according to configuration's repairing flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7451
diff
changeset
|
67 |
|
0 | 68 |
|
7451
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
69 |
class transaction(object): |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
70 |
"""Ensure that the transaction is either commited or rollbacked at exit |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
71 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
72 |
Context manager to enter a transaction for a session: when exiting the |
7451
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
73 |
`with` block on exception, call `session.rollback()`, else call |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
74 |
`session.commit()` on normal exit |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
75 |
""" |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
76 |
def __init__(self, session, free_cnxset=True): |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
77 |
self.session = session |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
78 |
self.free_cnxset = free_cnxset |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
79 |
|
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
80 |
def __enter__(self): |
8529
1daea1f433c9
[datafeed] make cnxset handling of datafeed source more robust
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8433
diff
changeset
|
81 |
# ensure session has a cnxset |
1daea1f433c9
[datafeed] make cnxset handling of datafeed source more robust
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8433
diff
changeset
|
82 |
self.session.set_cnxset() |
7451
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
83 |
|
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
84 |
def __exit__(self, exctype, exc, traceback): |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
85 |
if exctype: |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
86 |
self.session.rollback(free_cnxset=self.free_cnxset) |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
87 |
else: |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
88 |
self.session.commit(free_cnxset=self.free_cnxset) |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
89 |
|
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
90 |
|
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
91 |
class hooks_control(object): |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
92 |
"""context manager to control activated hooks categories. |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
93 |
|
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
94 |
If mode is session.`HOOKS_DENY_ALL`, given hooks categories will |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
95 |
be enabled. |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
96 |
|
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
97 |
If mode is session.`HOOKS_ALLOW_ALL`, given hooks categories will |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
98 |
be disabled. |
6147
95c604ec89bf
update documentation to follow 6142:8bc6eac1fac1 changes. Try to make it better and move most doc with code on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
99 |
|
95c604ec89bf
update documentation to follow 6142:8bc6eac1fac1 changes. Try to make it better and move most doc with code on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
100 |
.. sourcecode:: python |
95c604ec89bf
update documentation to follow 6142:8bc6eac1fac1 changes. Try to make it better and move most doc with code on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
101 |
|
95c604ec89bf
update documentation to follow 6142:8bc6eac1fac1 changes. Try to make it better and move most doc with code on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
102 |
with hooks_control(self.session, self.session.HOOKS_ALLOW_ALL, 'integrity'): |
95c604ec89bf
update documentation to follow 6142:8bc6eac1fac1 changes. Try to make it better and move most doc with code on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
103 |
# ... do stuff with all but 'integrity' hooks activated |
95c604ec89bf
update documentation to follow 6142:8bc6eac1fac1 changes. Try to make it better and move most doc with code on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
104 |
|
95c604ec89bf
update documentation to follow 6142:8bc6eac1fac1 changes. Try to make it better and move most doc with code on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
105 |
with hooks_control(self.session, self.session.HOOKS_DENY_ALL, 'integrity'): |
95c604ec89bf
update documentation to follow 6142:8bc6eac1fac1 changes. Try to make it better and move most doc with code on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6142
diff
changeset
|
106 |
# ... do stuff with none but 'integrity' hooks activated |
8561
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
107 |
|
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
108 |
This is an internal api, you should rather use |
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
109 |
:meth:`~cubicweb.server.session.Session.deny_all_hooks_but` or |
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
110 |
:meth:`~cubicweb.server.session.Session.allow_all_hooks_but` session |
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
111 |
methods. |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
112 |
""" |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
113 |
def __init__(self, session, mode, *categories): |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
114 |
self.session = session |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
115 |
self.mode = mode |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
116 |
self.categories = categories |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
117 |
|
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
118 |
def __enter__(self): |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
119 |
self.oldmode, self.changes = self.session.init_hooks_mode_categories( |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
120 |
self.mode, self.categories) |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
121 |
|
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
122 |
def __exit__(self, exctype, exc, traceback): |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
123 |
self.session.reset_hooks_mode_categories(self.oldmode, self.mode, self.changes) |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
124 |
|
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
125 |
|
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
126 |
class security_enabled(object): |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
127 |
"""context manager to control security w/ session.execute, |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
128 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
129 |
By default security is disabled on queries executed on the repository |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
130 |
side. |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
131 |
""" |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
132 |
def __init__(self, session, read=None, write=None): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
133 |
self.session = session |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
134 |
self.read = read |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
135 |
self.write = write |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
136 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
137 |
def __enter__(self): |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
138 |
self.oldread, self.oldwrite = self.session.init_security( |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
139 |
self.read, self.write) |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
140 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
141 |
def __exit__(self, exctype, exc, traceback): |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
142 |
self.session.reset_security(self.oldread, self.oldwrite) |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
143 |
|
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
144 |
|
8761
9c6fb10d246a
[server] rename TransactionData to Transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8760
diff
changeset
|
145 |
class Transaction(object): |
8762
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
146 |
"""Repository Transaction |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
147 |
|
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
148 |
Holds all transaction related data |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
149 |
|
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
150 |
Database connections resource: |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
151 |
|
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
152 |
:attr:`cnxset`, the connections set to use to execute queries on sources. |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
153 |
If the transaction is read only, the connection set may be freed between |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
154 |
actual query. This allows multiple transaction with a reasonable low |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
155 |
connection set pool size. control mechanism is detailed below |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
156 |
|
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
157 |
:attr:`mode`, string telling the connections set handling mode, may be one |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
158 |
of 'read' (connections set may be freed), 'write' (some write was done in |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
159 |
the connections set, it can't be freed before end of the transaction), |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
160 |
'transaction' (we want to keep the connections set during all the |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
161 |
transaction, with or without writing) |
8764
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
162 |
|
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
163 |
Internal transaction data: |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
164 |
|
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
165 |
:attr:`transaction_data`,is a dictionary containing some shared data |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
166 |
cleared at the end of the transaction. Hooks and operations may put |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
167 |
arbitrary data in there, and this may also be used as a communication |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
168 |
channel between the client and the repository. |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
169 |
|
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
170 |
:attr:`pending_operations`, ordered list of operations to be processed on |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
171 |
commit/rollback |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
172 |
|
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
173 |
:attr:`commit_state`, describing the transaction commit state, may be one |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
174 |
of None (not yet committing), 'precommit' (calling precommit event on |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
175 |
operations), 'postcommit' (calling postcommit event on operations), |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
176 |
'uncommitable' (some :exc:`ValidationError` or :exc:`Unauthorized` error |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
177 |
has been raised during the transaction and so it must be rollbacked). |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
178 |
|
8762
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
179 |
""" |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
180 |
|
8763
0144b26e958d
[transaction] handle ``mode`` default value in Transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8762
diff
changeset
|
181 |
def __init__(self, txid, mode='read'): |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
182 |
#: transaction unique id |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
183 |
self.transactionid = txid |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
184 |
#: reentrance handling |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
185 |
self.ctx_count = 0 |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
186 |
|
8762
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
187 |
#: connection handling mode |
8763
0144b26e958d
[transaction] handle ``mode`` default value in Transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8762
diff
changeset
|
188 |
self.mode = mode |
8762
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
189 |
#: connection set used to execute queries on sources |
6b397a0ba1d6
[transaction] explicit Transaction cnxset attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8761
diff
changeset
|
190 |
self.cnxset = None |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
191 |
|
8764
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
192 |
#: dict containing arbitrary data cleared at the end of the transaction |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
193 |
self.transaction_data = {} |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
194 |
#: ordered list of operations to be processed on commit/rollback |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
195 |
self.pending_operations = [] |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
196 |
#: (None, 'precommit', 'postcommit', 'uncommitable') |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
197 |
self.commit_state = None |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
198 |
|
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
199 |
def clear(self): |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
200 |
"""reset internal data""" |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
201 |
self.transaction_data = {} |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
202 |
#: ordered list of operations to be processed on commit/rollback |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
203 |
self.pending_operations = [] |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
204 |
#: (None, 'precommit', 'postcommit', 'uncommitable') |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
205 |
self.commit_state = None |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
206 |
|
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
207 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2788
diff
changeset
|
208 |
class Session(RequestSessionBase): |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
209 |
"""Repository user session |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
210 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
211 |
This tie all together: |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
212 |
* session id, |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
213 |
* user, |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
214 |
* connections set, |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
215 |
* other session data. |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
216 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
217 |
About session storage / transactions |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
218 |
------------------------------------ |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
219 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
220 |
Here is a description of internal session attributes. Besides :attr:`data` |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
221 |
and :attr:`transaction_data`, you should not have to use attributes |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
222 |
described here but higher level APIs. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
223 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
224 |
:attr:`data` is a dictionary containing shared data, used to communicate |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
225 |
extra information between the client and the repository |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
226 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
227 |
:attr:`_tx_data` is a dictionary of :class:`TransactionData` instance, one |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
228 |
for each running transaction. The key is the transaction id. By default |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
229 |
the transaction id is the thread name but it can be otherwise (per dbapi |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
230 |
cursor for instance, or per thread name *from another process*). |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
231 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
232 |
:attr:`__threaddata` is a thread local storage whose `txdata` attribute |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
233 |
refers to the proper instance of :class:`TransactionData` according to the |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
234 |
transaction. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
235 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
236 |
:attr:`_threads_in_transaction` is a set of (thread, connections set) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
237 |
referencing threads that currently hold a connections set for the session. |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
238 |
.. automethod:: cubicweb.server.session.transaction |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
239 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
240 |
You should not have to use neither :attr:`_txdata` nor :attr:`__threaddata`, |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
241 |
simply access transaction data transparently through the :attr:`_threaddata` |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
242 |
property. Also, you usually don't have to access it directly since current |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
243 |
transaction's data may be accessed/modified through properties / methods: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
244 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
245 |
:attr:`transaction_data`, similarly to :attr:`data`, is a dictionary |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
246 |
containing some shared data that should be cleared at the end of the |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
247 |
transaction. Hooks and operations may put arbitrary data in there, and |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
248 |
this may also be used as a communication channel between the client and |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
249 |
the repository. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
250 |
|
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
251 |
.. automethod:: cubicweb.server.session.Session.get_shared_data |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
252 |
.. automethod:: cubicweb.server.session.Session.set_shared_data |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
253 |
.. automethod:: cubicweb.server.session.Session.added_in_transaction |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
254 |
.. automethod:: cubicweb.server.session.Session.deleted_in_transaction |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
255 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
256 |
Transaction state information: |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
257 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
258 |
:attr:`running_dbapi_query`, boolean flag telling if the executing query |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
259 |
is coming from a dbapi connection or is a query from within the repository |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
260 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
261 |
:attr:`cnxset`, the connections set to use to execute queries on sources. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
262 |
During a transaction, the connection set may be freed so that is may be |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
263 |
used by another session as long as no writing is done. This means we can |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
264 |
have multiple sessions with a reasonably low connections set pool size. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
265 |
|
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
266 |
.. automethod:: cubicweb.server.session.set_cnxset |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
267 |
.. automethod:: cubicweb.server.session.free_cnxset |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
268 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
269 |
:attr:`mode`, string telling the connections set handling mode, may be one |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
270 |
of 'read' (connections set may be freed), 'write' (some write was done in |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
271 |
the connections set, it can't be freed before end of the transaction), |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
272 |
'transaction' (we want to keep the connections set during all the |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
273 |
transaction, with or without writing) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
274 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
275 |
:attr:`pending_operations`, ordered list of operations to be processed on |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
276 |
commit/rollback |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
277 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
278 |
:attr:`commit_state`, describing the transaction commit state, may be one |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
279 |
of None (not yet committing), 'precommit' (calling precommit event on |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
280 |
operations), 'postcommit' (calling postcommit event on operations), |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
281 |
'uncommitable' (some :exc:`ValidationError` or :exc:`Unauthorized` error |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
282 |
has been raised during the transaction and so it must be rollbacked). |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
283 |
|
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
284 |
.. automethod:: cubicweb.server.session.Session.commit |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
285 |
.. automethod:: cubicweb.server.session.Session.rollback |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
286 |
.. automethod:: cubicweb.server.session.Session.close |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
287 |
.. automethod:: cubicweb.server.session.Session.closed |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
288 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
289 |
Security level Management: |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
290 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
291 |
:attr:`read_security` and :attr:`write_security`, boolean flags telling if |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
292 |
read/write security is currently activated. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
293 |
|
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
294 |
.. automethod:: cubicweb.server.session.Session.set_write_security |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
295 |
.. automethod:: cubicweb.server.session.Session.set_read_security |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
296 |
.. automethod:: cubicweb.server.session.Session.init_security |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
297 |
.. automethod:: cubicweb.server.session.Session.reset_security |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
298 |
.. automethod:: cubicweb.server.session.Session.security_enabled |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
299 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
300 |
Hooks Management: |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
301 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
302 |
:attr:`hooks_mode`, may be either `HOOKS_ALLOW_ALL` or `HOOKS_DENY_ALL`. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
303 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
304 |
:attr:`enabled_hook_categories`, when :attr:`hooks_mode` is |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
305 |
`HOOKS_DENY_ALL`, this set contains hooks categories that are enabled. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
306 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
307 |
:attr:`disabled_hook_categories`, when :attr:`hooks_mode` is |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
308 |
`HOOKS_ALLOW_ALL`, this set contains hooks categories that are disabled. |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
309 |
|
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
310 |
.. automethod:: cubicweb.server.session.Session.deny_all_hooks_but |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
311 |
.. automethod:: cubicweb.server.session.Session.allow_all_hooks_but |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
312 |
.. automethod:: cubicweb.server.session.Session.is_hook_category_activated |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
313 |
.. automethod:: cubicweb.server.session.Session.is_hook_activated |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
314 |
|
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
315 |
Data manipulation: |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
316 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
317 |
.. automethod:: cubicweb.server.session.Session.add_relation |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
318 |
.. automethod:: cubicweb.server.session.Session.add_relations |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
319 |
.. automethod:: cubicweb.server.session.Session.delete_relation |
8561
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
320 |
|
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
321 |
Other: |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
322 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
323 |
.. automethod:: cubicweb.server.session.Session.call_service |
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
324 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
325 |
|
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
326 |
|
0 | 327 |
""" |
8525
c09feae04094
[entity edition] don't remove values from attribute cache on the repository side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8433
diff
changeset
|
328 |
is_request = False |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
329 |
is_internal_session = False |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
330 |
|
0 | 331 |
def __init__(self, user, repo, cnxprops=None, _id=None): |
332 |
super(Session, self).__init__(repo.vreg) |
|
7769
8af09eeee130
[session] take care of non-ascii characters in login and session id (closes: #1910849)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7757
diff
changeset
|
333 |
self.id = _id or make_uid(unormalize(user.login).encode('UTF8')) |
0 | 334 |
self.user = user |
335 |
self.repo = repo |
|
5792
e13aa4786a72
[session] update session's timestamp in session.execute, so long running transactions are not erroneously closed by the repository
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5791
diff
changeset
|
336 |
self.timestamp = time() |
2570
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
337 |
self.default_mode = 'read' |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
338 |
# undo support |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
339 |
if repo.config.creating or repo.config.repairing or self.is_internal_session: |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
340 |
self.undo_actions = False |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
341 |
else: |
8306
4da49700b06a
[config, undo] Fix undo-support option migration
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8265
diff
changeset
|
342 |
self.undo_actions = repo.config['undo-enabled'] |
0 | 343 |
# short cut to querier .execute method |
344 |
self._execute = repo.querier.execute |
|
345 |
# shared data, used to communicate extra information between the client |
|
346 |
# and the rql server |
|
347 |
self.data = {} |
|
348 |
# i18n initialization |
|
8538
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8535
diff
changeset
|
349 |
self.set_language(user.prefered_language()) |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
350 |
# internals |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
351 |
self._tx_data = {} |
8760
17994bf95d6a
[doc] update Session documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
352 |
# Data local to the thread |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
353 |
self.__threaddata = threading.local() |
1880
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
354 |
self._threads_in_transaction = set() |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
355 |
self._closed = False |
7340
9303fd71c2ee
[session] lock self._closed and session.close to avoid race conditions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
356 |
self._closed_lock = threading.Lock() |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
357 |
|
4703
4e803c30b7db
[session] user.login is usually an unicode string, so implements __unicode__ instead of __str__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4533
diff
changeset
|
358 |
def __unicode__(self): |
8669
62213a34726e
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8626
diff
changeset
|
359 |
return '<session %s (%s 0x%x)>' % ( |
62213a34726e
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8626
diff
changeset
|
360 |
unicode(self.user.login), self.id, id(self)) |
2604
6b55a2a81fd8
[R repo session] add_relation method use in hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2603
diff
changeset
|
361 |
|
7451
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
362 |
def transaction(self, free_cnxset=True): |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
363 |
"""return context manager to enter a transaction for the session: when |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
364 |
exiting the `with` block on exception, call `session.rollback()`, else |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
365 |
call `session.commit()` on normal exit. |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
366 |
|
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
367 |
The `free_cnxset` will be given to rollback/commit methods to indicate |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
368 |
wether the connections set should be freed or not. |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
369 |
""" |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
370 |
return transaction(self, free_cnxset) |
48ba5f0c11de
[session] provide a simple transaction context manager for session. Closes #1725640
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7405
diff
changeset
|
371 |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
372 |
def set_tx_data(self, txid=None): |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
373 |
if txid is None: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
374 |
txid = threading.currentThread().getName() |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
375 |
try: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
376 |
self.__threaddata.txdata = self._tx_data[txid] |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
377 |
except KeyError: |
8763
0144b26e958d
[transaction] handle ``mode`` default value in Transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8762
diff
changeset
|
378 |
tx = Transaction(txid, self.default_mode) |
0144b26e958d
[transaction] handle ``mode`` default value in Transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8762
diff
changeset
|
379 |
self.__threaddata.txdata = self._tx_data[txid] = tx |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
380 |
|
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
381 |
@property |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
382 |
def _threaddata(self): |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
383 |
try: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
384 |
return self.__threaddata.txdata |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
385 |
except AttributeError: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
386 |
self.set_tx_data() |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
387 |
return self.__threaddata.txdata |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
388 |
|
8585
3f60f416dddb
[dbapi] provide get_option_value over DBAPIRequest (closes #2515522)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8529
diff
changeset
|
389 |
def get_option_value(self, option, foreid=None): |
3f60f416dddb
[dbapi] provide get_option_value over DBAPIRequest (closes #2515522)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8529
diff
changeset
|
390 |
return self.repo.get_option_value(option, foreid) |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
391 |
|
3112
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
392 |
def hijack_user(self, user): |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
393 |
"""return a fake request/session using specified user""" |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
394 |
session = Session(user, self.repo) |
4924
d2fc161bee3f
[session] fix hijack_user: most transaction_data should be copied (everything but the entity cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
395 |
threaddata = session._threaddata |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
396 |
threaddata.cnxset = self.cnxset |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
397 |
# we attributed a connections set, need to update ctx_count else it will be freed |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
398 |
# while undesired |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
399 |
threaddata.ctx_count = 1 |
4992
398cc8b39aec
backport pending_operations on hi-jacked session, see comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4987
diff
changeset
|
400 |
# share pending_operations, else operation added in the hi-jacked |
398cc8b39aec
backport pending_operations on hi-jacked session, see comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4987
diff
changeset
|
401 |
# session such as SendMailOp won't ever be processed |
398cc8b39aec
backport pending_operations on hi-jacked session, see comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4987
diff
changeset
|
402 |
threaddata.pending_operations = self.pending_operations |
4924
d2fc161bee3f
[session] fix hijack_user: most transaction_data should be copied (everything but the entity cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
403 |
# everything in transaction_data should be copied back but the entity |
d2fc161bee3f
[session] fix hijack_user: most transaction_data should be copied (everything but the entity cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
404 |
# type cache we don't want to avoid security pb |
d2fc161bee3f
[session] fix hijack_user: most transaction_data should be copied (everything but the entity cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
405 |
threaddata.transaction_data = self.transaction_data.copy() |
d2fc161bee3f
[session] fix hijack_user: most transaction_data should be copied (everything but the entity cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
406 |
threaddata.transaction_data.pop('ecache', None) |
3112
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
407 |
return session |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
408 |
|
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
409 |
def add_relation(self, fromeid, rtype, toeid): |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
410 |
"""provide direct access to the repository method to add a relation. |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
411 |
|
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
412 |
This is equivalent to the following rql query: |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
413 |
|
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
414 |
SET X rtype Y WHERE X eid fromeid, T eid toeid |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
415 |
|
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
416 |
without read security check but also all the burden of rql execution. |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
417 |
You may use this in hooks when you know both eids of the relation you |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
418 |
want to add. |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
419 |
""" |
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
420 |
self.add_relations([(rtype, [(fromeid, toeid)])]) |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
421 |
|
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
422 |
def add_relations(self, relations): |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
423 |
'''set many relation using a shortcut similar to the one in add_relation |
7526
ae31063f3274
cleanup and assert we don't import unexpected stuff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7502
diff
changeset
|
424 |
|
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
425 |
relations is a list of 2-uples, the first element of each |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
426 |
2-uple is the rtype, and the second is a list of (fromeid, |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
427 |
toeid) tuples |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
428 |
''' |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
429 |
edited_entities = {} |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
430 |
relations_dict = {} |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
431 |
with security_enabled(self, False, False): |
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
432 |
for rtype, eids in relations: |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
433 |
if self.vreg.schema[rtype].inlined: |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
434 |
for fromeid, toeid in eids: |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
435 |
if fromeid not in edited_entities: |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
436 |
entity = self.entity_from_eid(fromeid) |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
437 |
edited = EditedEntity(entity) |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
438 |
edited_entities[fromeid] = edited |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
439 |
else: |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
440 |
edited = edited_entities[fromeid] |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
441 |
edited.edited_attribute(rtype, toeid) |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
442 |
else: |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
443 |
relations_dict[rtype] = eids |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
444 |
self.repo.glob_add_relations(self, relations_dict) |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
445 |
for edited in edited_entities.itervalues(): |
7119
8b29c4c2ffc6
[repository] fix crash in optimized [add|remove]_relation w/ inlined relation (broken by cw 3.10 refactoring)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7118
diff
changeset
|
446 |
self.repo.glob_update_entity(self, edited) |
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7119
diff
changeset
|
447 |
|
3197
b27d19c0db1c
[repo] take care of inlined relation in session.[add|delete]_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3196
diff
changeset
|
448 |
|
3112
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
449 |
def delete_relation(self, fromeid, rtype, toeid): |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
450 |
"""provide direct access to the repository method to delete a relation. |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
451 |
|
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
452 |
This is equivalent to the following rql query: |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
453 |
|
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
454 |
DELETE X rtype Y WHERE X eid fromeid, T eid toeid |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
455 |
|
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
456 |
without read security check but also all the burden of rql execution. |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
457 |
You may use this in hooks when you know both eids of the relation you |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
458 |
want to delete. |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
459 |
""" |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
460 |
with security_enabled(self, False, False): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
461 |
if self.vreg.schema[rtype].inlined: |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
462 |
entity = self.entity_from_eid(fromeid) |
7119
8b29c4c2ffc6
[repository] fix crash in optimized [add|remove]_relation w/ inlined relation (broken by cw 3.10 refactoring)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7118
diff
changeset
|
463 |
entity.cw_attr_cache[rtype] = None |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
464 |
self.repo.glob_update_entity(self, entity, set((rtype,))) |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
465 |
else: |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
466 |
self.repo.glob_delete_relation(self, fromeid, rtype, toeid) |
3112
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
467 |
|
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
468 |
# relations cache handling ################################################# |
873202e181bb
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3074
diff
changeset
|
469 |
|
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
470 |
def update_rel_cache_add(self, subject, rtype, object, symmetric=False): |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
471 |
self._update_entity_rel_cache_add(subject, rtype, 'subject', object) |
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
472 |
if symmetric: |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
473 |
self._update_entity_rel_cache_add(object, rtype, 'subject', subject) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
474 |
else: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
475 |
self._update_entity_rel_cache_add(object, rtype, 'object', subject) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
476 |
|
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
477 |
def update_rel_cache_del(self, subject, rtype, object, symmetric=False): |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
478 |
self._update_entity_rel_cache_del(subject, rtype, 'subject', object) |
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
479 |
if symmetric: |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
480 |
self._update_entity_rel_cache_del(object, rtype, 'object', object) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
481 |
else: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
482 |
self._update_entity_rel_cache_del(object, rtype, 'object', subject) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
483 |
|
3553
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
484 |
def _update_entity_rel_cache_add(self, eid, rtype, role, targeteid): |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
485 |
try: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
486 |
entity = self.entity_cache(eid) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
487 |
except KeyError: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
488 |
return |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
489 |
rcache = entity.cw_relation_cached(rtype, role) |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
490 |
if rcache is not None: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
491 |
rset, entities = rcache |
3553
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
492 |
rset = rset.copy() |
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
493 |
entities = list(entities) |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
494 |
rset.rows.append([targeteid]) |
2781
4e1ad9d6a3e7
[session cache] always append to description, turn it into a list if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2764
diff
changeset
|
495 |
if not isinstance(rset.description, list): # else description not set |
4e1ad9d6a3e7
[session cache] always append to description, turn it into a list if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2764
diff
changeset
|
496 |
rset.description = list(rset.description) |
4e1ad9d6a3e7
[session cache] always append to description, turn it into a list if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2764
diff
changeset
|
497 |
rset.description.append([self.describe(targeteid)[0]]) |
3196
77936fa67ae6
[repo] set entity.rset & co when needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3161
diff
changeset
|
498 |
targetentity = self.entity_from_eid(targeteid) |
3379
9192ba07890d
use .cw_rset instead of rset on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3373
diff
changeset
|
499 |
if targetentity.cw_rset is None: |
3373
3cd644bfab12
use 3.6 attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
500 |
targetentity.cw_rset = rset |
3cd644bfab12
use 3.6 attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
501 |
targetentity.cw_row = rset.rowcount |
3cd644bfab12
use 3.6 attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
502 |
targetentity.cw_col = 0 |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
503 |
rset.rowcount += 1 |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
504 |
entities.append(targetentity) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
505 |
entity._cw_related_cache['%s_%s' % (rtype, role)] = ( |
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
506 |
rset, tuple(entities)) |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
507 |
|
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
508 |
def _update_entity_rel_cache_del(self, eid, rtype, role, targeteid): |
3553
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
509 |
try: |
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
510 |
entity = self.entity_cache(eid) |
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
511 |
except KeyError: |
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
512 |
return |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
513 |
rcache = entity.cw_relation_cached(rtype, role) |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
514 |
if rcache is not None: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
515 |
rset, entities = rcache |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
516 |
for idx, row in enumerate(rset.rows): |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
517 |
if row[0] == targeteid: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
518 |
break |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
519 |
else: |
3074
141cfaac6b97
don't fail when trying to update relation cache for relation deletion, this may occurs regularly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2874
diff
changeset
|
520 |
# this may occurs if the cache has been filed by a hook |
141cfaac6b97
don't fail when trying to update relation cache for relation deletion, this may occurs regularly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2874
diff
changeset
|
521 |
# after the database update |
141cfaac6b97
don't fail when trying to update relation cache for relation deletion, this may occurs regularly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2874
diff
changeset
|
522 |
self.debug('cache inconsistency for %s %s %s %s', eid, rtype, |
141cfaac6b97
don't fail when trying to update relation cache for relation deletion, this may occurs regularly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2874
diff
changeset
|
523 |
role, targeteid) |
141cfaac6b97
don't fail when trying to update relation cache for relation deletion, this may occurs regularly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2874
diff
changeset
|
524 |
return |
3553
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
525 |
rset = rset.copy() |
76b4a177a018
[session cache] ensure we're not modifying cached rset/entities, they may be used elsewhere
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3275
diff
changeset
|
526 |
entities = list(entities) |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
527 |
del rset.rows[idx] |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
528 |
if isinstance(rset.description, list): # else description not set |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
529 |
del rset.description[idx] |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
530 |
del entities[idx] |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
531 |
rset.rowcount -= 1 |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
532 |
entity._cw_related_cache['%s_%s' % (rtype, role)] = ( |
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
533 |
rset, tuple(entities)) |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
534 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
535 |
# resource accessors ###################################################### |
0 | 536 |
|
2623
e1f34b77290b
oops, should have been in a earlier commit (give rollback_on_failure to doexec)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2616
diff
changeset
|
537 |
def system_sql(self, sql, args=None, rollback_on_failure=True): |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
538 |
"""return a sql cursor on the system database""" |
5226
2e215efcc3a6
[session] better readability
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5193
diff
changeset
|
539 |
if sql.split(None, 1)[0].upper() != 'SELECT': |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
540 |
self.mode = 'write' |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
541 |
source = self.cnxset.source('system') |
5108
8495d580a580
[session] try to reconnect on unexpected error in system_sql. We need this for proper reconnection of pool used by hooks or looping task doing sql queries (such as cw_cleanup_transaction)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5074
diff
changeset
|
542 |
try: |
8495d580a580
[session] try to reconnect on unexpected error in system_sql. We need this for proper reconnection of pool used by hooks or looping task doing sql queries (such as cw_cleanup_transaction)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5074
diff
changeset
|
543 |
return source.doexec(self, sql, args, rollback=rollback_on_failure) |
8495d580a580
[session] try to reconnect on unexpected error in system_sql. We need this for proper reconnection of pool used by hooks or looping task doing sql queries (such as cw_cleanup_transaction)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5074
diff
changeset
|
544 |
except (source.OperationalError, source.InterfaceError): |
5802
159b6a712d9d
[session] when rollback_on_failure is false, we should not try to reconnect if the sql raised an error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5792
diff
changeset
|
545 |
if not rollback_on_failure: |
159b6a712d9d
[session] when rollback_on_failure is false, we should not try to reconnect if the sql raised an error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5792
diff
changeset
|
546 |
raise |
5108
8495d580a580
[session] try to reconnect on unexpected error in system_sql. We need this for proper reconnection of pool used by hooks or looping task doing sql queries (such as cw_cleanup_transaction)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5074
diff
changeset
|
547 |
source.warning("trying to reconnect") |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
548 |
self.cnxset.reconnect(source) |
5108
8495d580a580
[session] try to reconnect on unexpected error in system_sql. We need this for proper reconnection of pool used by hooks or looping task doing sql queries (such as cw_cleanup_transaction)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5074
diff
changeset
|
549 |
return source.doexec(self, sql, args, rollback=rollback_on_failure) |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
550 |
|
2840
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
551 |
def deleted_in_transaction(self, eid): |
4842 | 552 |
"""return True if the entity of the given eid is being deleted in the |
553 |
current transaction |
|
554 |
""" |
|
2840
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
555 |
return eid in self.transaction_data.get('pendingeids', ()) |
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
556 |
|
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
557 |
def added_in_transaction(self, eid): |
4842 | 558 |
"""return True if the entity of the given eid is being created in the |
559 |
current transaction |
|
560 |
""" |
|
2840
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
561 |
return eid in self.transaction_data.get('neweids', ()) |
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
562 |
|
7502
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
563 |
def rtype_eids_rdef(self, rtype, eidfrom, eidto): |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
564 |
# use type_and_source_from_eid instead of type_from_eid for optimization |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
565 |
# (avoid two extra methods call) |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
566 |
subjtype = self.repo.type_and_source_from_eid(eidfrom, self)[0] |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
567 |
objtype = self.repo.type_and_source_from_eid(eidto, self)[0] |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
568 |
return self.vreg.schema.rschema(rtype).rdefs[(subjtype, objtype)] |
2840
06daf13195d4
[hooks] deprecates hookhelper module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
569 |
|
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
570 |
# security control ######################################################### |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
571 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
572 |
DEFAULT_SECURITY = object() # evaluated to true by design |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
573 |
|
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8561
diff
changeset
|
574 |
def security_enabled(self, read=None, write=None): |
7405
8c752d113ebb
[session] new methods on session to ease access to security/hooks control context managers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7340
diff
changeset
|
575 |
return security_enabled(self, read=read, write=write) |
8c752d113ebb
[session] new methods on session to ease access to security/hooks control context managers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7340
diff
changeset
|
576 |
|
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
577 |
def init_security(self, read, write): |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
578 |
if read is None: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
579 |
oldread = None |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
580 |
else: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
581 |
oldread = self.set_read_security(read) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
582 |
if write is None: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
583 |
oldwrite = None |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
584 |
else: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
585 |
oldwrite = self.set_write_security(write) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
586 |
self._threaddata.ctx_count += 1 |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
587 |
return oldread, oldwrite |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
588 |
|
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
589 |
def reset_security(self, read, write): |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
590 |
txstore = self._threaddata |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
591 |
txstore.ctx_count -= 1 |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
592 |
if txstore.ctx_count == 0: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
593 |
self._clear_thread_storage(txstore) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
594 |
else: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
595 |
if read is not None: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
596 |
self.set_read_security(read) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
597 |
if write is not None: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
598 |
self.set_write_security(write) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
599 |
|
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
600 |
@property |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
601 |
def read_security(self): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
602 |
"""return a boolean telling if read security is activated or not""" |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
603 |
txstore = self._threaddata |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
604 |
if txstore is None: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
605 |
return self.DEFAULT_SECURITY |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
606 |
try: |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
607 |
return txstore.read_security |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
608 |
except AttributeError: |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
609 |
txstore.read_security = self.DEFAULT_SECURITY |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
610 |
return txstore.read_security |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
611 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
612 |
def set_read_security(self, activated): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
613 |
"""[de]activate read security, returning the previous value set for |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
614 |
later restoration. |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
615 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
616 |
you should usually use the `security_enabled` context manager instead |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
617 |
of this to change security settings. |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
618 |
""" |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
619 |
txstore = self._threaddata |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
620 |
if txstore is None: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
621 |
return self.DEFAULT_SECURITY |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
622 |
oldmode = getattr(txstore, 'read_security', self.DEFAULT_SECURITY) |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
623 |
txstore.read_security = activated |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
624 |
# dbapi_query used to detect hooks triggered by a 'dbapi' query (eg not |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
625 |
# issued on the session). This is tricky since we the execution model of |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
626 |
# a (write) user query is: |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
627 |
# |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
628 |
# repository.execute (security enabled) |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
629 |
# \-> querier.execute |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
630 |
# \-> repo.glob_xxx (add/update/delete entity/relation) |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
631 |
# \-> deactivate security before calling hooks |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
632 |
# \-> WE WANT TO CHECK QUERY NATURE HERE |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
633 |
# \-> potentially, other calls to querier.execute |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
634 |
# |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
635 |
# so we can't rely on simply checking session.read_security, but |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
636 |
# recalling the first transition from DEFAULT_SECURITY to something |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
637 |
# else (False actually) is not perfect but should be enough |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
638 |
# |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
639 |
# also reset dbapi_query to true when we go back to DEFAULT_SECURITY |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
640 |
txstore.dbapi_query = (oldmode is self.DEFAULT_SECURITY |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
641 |
or activated is self.DEFAULT_SECURITY) |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
642 |
return oldmode |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
643 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
644 |
@property |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
645 |
def write_security(self): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
646 |
"""return a boolean telling if write security is activated or not""" |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
647 |
txstore = self._threaddata |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
648 |
if txstore is None: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
649 |
return self.DEFAULT_SECURITY |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
650 |
try: |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
651 |
return txstore.write_security |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
652 |
except AttributeError: |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
653 |
txstore.write_security = self.DEFAULT_SECURITY |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
654 |
return txstore.write_security |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
655 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
656 |
def set_write_security(self, activated): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
657 |
"""[de]activate write security, returning the previous value set for |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
658 |
later restoration. |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
659 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
660 |
you should usually use the `security_enabled` context manager instead |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
661 |
of this to change security settings. |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
662 |
""" |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
663 |
txstore = self._threaddata |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
664 |
if txstore is None: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
665 |
return self.DEFAULT_SECURITY |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
666 |
oldmode = getattr(txstore, 'write_security', self.DEFAULT_SECURITY) |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
667 |
txstore.write_security = activated |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
668 |
return oldmode |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
669 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
670 |
@property |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
671 |
def running_dbapi_query(self): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
672 |
"""return a boolean telling if it's triggered by a db-api query or by |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
673 |
a session query. |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
674 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
675 |
To be used in hooks, else may have a wrong value. |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
676 |
""" |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
677 |
return getattr(self._threaddata, 'dbapi_query', True) |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
678 |
|
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
679 |
# hooks activation control ################################################# |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
680 |
# all hooks should be activated during normal execution |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
681 |
|
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
682 |
HOOKS_ALLOW_ALL = object() |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
683 |
HOOKS_DENY_ALL = object() |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
684 |
|
7405
8c752d113ebb
[session] new methods on session to ease access to security/hooks control context managers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7340
diff
changeset
|
685 |
def allow_all_hooks_but(self, *categories): |
8c752d113ebb
[session] new methods on session to ease access to security/hooks control context managers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7340
diff
changeset
|
686 |
return hooks_control(self, self.HOOKS_ALLOW_ALL, *categories) |
8c752d113ebb
[session] new methods on session to ease access to security/hooks control context managers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7340
diff
changeset
|
687 |
def deny_all_hooks_but(self, *categories): |
8c752d113ebb
[session] new methods on session to ease access to security/hooks control context managers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7340
diff
changeset
|
688 |
return hooks_control(self, self.HOOKS_DENY_ALL, *categories) |
8c752d113ebb
[session] new methods on session to ease access to security/hooks control context managers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7340
diff
changeset
|
689 |
|
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
690 |
@property |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
691 |
def hooks_mode(self): |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
692 |
return getattr(self._threaddata, 'hooks_mode', self.HOOKS_ALLOW_ALL) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
693 |
|
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
694 |
def set_hooks_mode(self, mode): |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
695 |
assert mode is self.HOOKS_ALLOW_ALL or mode is self.HOOKS_DENY_ALL |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
696 |
oldmode = getattr(self._threaddata, 'hooks_mode', self.HOOKS_ALLOW_ALL) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
697 |
self._threaddata.hooks_mode = mode |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
698 |
return oldmode |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
699 |
|
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
700 |
def init_hooks_mode_categories(self, mode, categories): |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
701 |
oldmode = self.set_hooks_mode(mode) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
702 |
if mode is self.HOOKS_DENY_ALL: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
703 |
changes = self.enable_hook_categories(*categories) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
704 |
else: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
705 |
changes = self.disable_hook_categories(*categories) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
706 |
self._threaddata.ctx_count += 1 |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
707 |
return oldmode, changes |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
708 |
|
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
709 |
def reset_hooks_mode_categories(self, oldmode, mode, categories): |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
710 |
txstore = self._threaddata |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
711 |
txstore.ctx_count -= 1 |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
712 |
if txstore.ctx_count == 0: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
713 |
self._clear_thread_storage(txstore) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
714 |
else: |
7757
5b3584c5a7c3
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7730
diff
changeset
|
715 |
try: |
5b3584c5a7c3
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7730
diff
changeset
|
716 |
if categories: |
5b3584c5a7c3
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7730
diff
changeset
|
717 |
if mode is self.HOOKS_DENY_ALL: |
5b3584c5a7c3
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7730
diff
changeset
|
718 |
return self.disable_hook_categories(*categories) |
5b3584c5a7c3
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7730
diff
changeset
|
719 |
else: |
5b3584c5a7c3
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7730
diff
changeset
|
720 |
return self.enable_hook_categories(*categories) |
5b3584c5a7c3
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7730
diff
changeset
|
721 |
finally: |
5b3584c5a7c3
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7730
diff
changeset
|
722 |
self.set_hooks_mode(oldmode) |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
723 |
|
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
724 |
@property |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
725 |
def disabled_hook_categories(self): |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
726 |
try: |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
727 |
return getattr(self._threaddata, 'disabled_hook_cats') |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
728 |
except AttributeError: |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
729 |
cats = self._threaddata.disabled_hook_cats = set() |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
730 |
return cats |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
731 |
|
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
732 |
@property |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
733 |
def enabled_hook_categories(self): |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
734 |
try: |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
735 |
return getattr(self._threaddata, 'enabled_hook_cats') |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
736 |
except AttributeError: |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
737 |
cats = self._threaddata.enabled_hook_cats = set() |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
738 |
return cats |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
739 |
|
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
740 |
def disable_hook_categories(self, *categories): |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
741 |
"""disable the given hook categories: |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
742 |
|
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
743 |
- on HOOKS_DENY_ALL mode, ensure those categories are not enabled |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
744 |
- on HOOKS_ALLOW_ALL mode, ensure those categories are disabled |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
745 |
""" |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
746 |
changes = set() |
7387
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
747 |
self.pruned_hooks_cache.clear() |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
748 |
if self.hooks_mode is self.HOOKS_DENY_ALL: |
7349
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
749 |
enabledcats = self.enabled_hook_categories |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
750 |
for category in categories: |
7349
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
751 |
if category in enabledcats: |
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
752 |
enabledcats.remove(category) |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
753 |
changes.add(category) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
754 |
else: |
7349
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
755 |
disabledcats = self.disabled_hook_categories |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
756 |
for category in categories: |
7349
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
757 |
if category not in disabledcats: |
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
758 |
disabledcats.add(category) |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
759 |
changes.add(category) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
760 |
return tuple(changes) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
761 |
|
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
762 |
def enable_hook_categories(self, *categories): |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
763 |
"""enable the given hook categories: |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
764 |
|
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
765 |
- on HOOKS_DENY_ALL mode, ensure those categories are enabled |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
766 |
- on HOOKS_ALLOW_ALL mode, ensure those categories are not disabled |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
767 |
""" |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
768 |
changes = set() |
7387
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
769 |
self.pruned_hooks_cache.clear() |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
770 |
if self.hooks_mode is self.HOOKS_DENY_ALL: |
7349
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
771 |
enabledcats = self.enabled_hook_categories |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
772 |
for category in categories: |
7349
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
773 |
if category not in enabledcats: |
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
774 |
enabledcats.add(category) |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
775 |
changes.add(category) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
776 |
else: |
7349
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
777 |
disabledcats = self.disabled_hook_categories |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
778 |
for category in categories: |
7349
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
779 |
if category in disabledcats: |
43416f63eca9
[session] nicer local variable names
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
780 |
disabledcats.remove(category) |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
781 |
changes.add(category) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
782 |
return tuple(changes) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
783 |
|
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
784 |
def is_hook_category_activated(self, category): |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
785 |
"""return a boolean telling if the given category is currently activated |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
786 |
or not |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
787 |
""" |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
788 |
if self.hooks_mode is self.HOOKS_DENY_ALL: |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
789 |
return category in self.enabled_hook_categories |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
790 |
return category not in self.disabled_hook_categories |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
791 |
|
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
792 |
def is_hook_activated(self, hook): |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
793 |
"""return a boolean telling if the given hook class is currently |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
794 |
activated or not |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
795 |
""" |
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
796 |
return self.is_hook_category_activated(hook.category) |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4767
diff
changeset
|
797 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
798 |
# connection management ################################################### |
0 | 799 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
800 |
def keep_cnxset_mode(self, mode): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
801 |
"""set `mode`, e.g. how the session will keep its connections set: |
2570
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
802 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
803 |
* if mode == 'write', the connections set is freed after each ready |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
804 |
query, but kept until the transaction's end (eg commit or rollback) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
805 |
when a write query is detected (eg INSERT/SET/DELETE queries) |
2570
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
806 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
807 |
* if mode == 'transaction', the connections set is only freed after the |
2570
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
808 |
transaction's end |
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
809 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
810 |
notice that a repository has a limited set of connections sets, and a |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
811 |
session has to wait for a free connections set to run any rql query |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
812 |
(unless it already has one set). |
2570
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
813 |
""" |
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
814 |
assert mode in ('transaction', 'write') |
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
815 |
if mode == 'transaction': |
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
816 |
self.default_mode = 'transaction' |
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
817 |
else: # mode == 'write' |
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
818 |
self.default_mode = 'read' |
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
819 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
820 |
def get_mode(self): |
8763
0144b26e958d
[transaction] handle ``mode`` default value in Transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8762
diff
changeset
|
821 |
return self._threaddata.mode |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
822 |
def set_mode(self, value): |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
823 |
self._threaddata.mode = value |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
824 |
mode = property(get_mode, set_mode, |
2570
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
825 |
doc='transaction mode (read/write/transaction), resetted to' |
80a996bb536d
[repo session] ability to ask session to keep it's pool set even when only read queries are done, necessary at least during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2319
diff
changeset
|
826 |
' default_mode on commit / rollback') |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
827 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
828 |
def get_commit_state(self): |
8764
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
829 |
return self._threaddata.commit_state |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
830 |
def set_commit_state(self, value): |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
831 |
self._threaddata.commit_state = value |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
832 |
commit_state = property(get_commit_state, set_commit_state) |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
833 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
834 |
@property |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
835 |
def cnxset(self): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
836 |
"""connections set, set according to transaction mode for each query""" |
5826
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
837 |
if self._closed: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
838 |
self.free_cnxset(True) |
7665
0cd299c16f12
[session] add session id to closed connection errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7574
diff
changeset
|
839 |
raise Exception('try to access connections set on a closed session %s' % self.id) |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
840 |
return getattr(self._threaddata, 'cnxset', None) |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
841 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
842 |
def set_cnxset(self): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
843 |
"""the session need a connections set to execute some queries""" |
7340
9303fd71c2ee
[session] lock self._closed and session.close to avoid race conditions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
844 |
with self._closed_lock: |
9303fd71c2ee
[session] lock self._closed and session.close to avoid race conditions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
845 |
if self._closed: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
846 |
self.free_cnxset(True) |
7665
0cd299c16f12
[session] add session id to closed connection errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7574
diff
changeset
|
847 |
raise Exception('try to set connections set on a closed session %s' % self.id) |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
848 |
if self.cnxset is None: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
849 |
# get connections set first to avoid race-condition |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
850 |
self._threaddata.cnxset = cnxset = self.repo._get_cnxset() |
7352 | 851 |
self._threaddata.ctx_count += 1 |
7340
9303fd71c2ee
[session] lock self._closed and session.close to avoid race conditions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
852 |
try: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
853 |
cnxset.cnxset_set() |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
854 |
except Exception: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
855 |
self._threaddata.cnxset = None |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
856 |
self.repo._free_cnxset(cnxset) |
7340
9303fd71c2ee
[session] lock self._closed and session.close to avoid race conditions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
857 |
raise |
9303fd71c2ee
[session] lock self._closed and session.close to avoid race conditions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
858 |
self._threads_in_transaction.add( |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
859 |
(threading.currentThread(), cnxset) ) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
860 |
return self._threaddata.cnxset |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
861 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
862 |
def _free_thread_cnxset(self, thread, cnxset, force_close=False): |
5826
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
863 |
try: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
864 |
self._threads_in_transaction.remove( (thread, cnxset) ) |
5826
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
865 |
except KeyError: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
866 |
# race condition on cnxset freeing (freed by commit or rollback vs |
5826
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
867 |
# close) |
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
868 |
pass |
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
869 |
else: |
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
870 |
if force_close: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
871 |
cnxset.reconnect() |
5826
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
872 |
else: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
873 |
cnxset.cnxset_freed() |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
874 |
# free cnxset once everything is done to avoid race-condition |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
875 |
self.repo._free_cnxset(cnxset) |
5826
462435bf5457
[session] refactor session handling so that when calling session.close(), pool of long running transaction of the same session is properly freed
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5813
diff
changeset
|
876 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
877 |
def free_cnxset(self, ignoremode=False): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
878 |
"""the session is no longer using its connections set, at least for some time""" |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
879 |
# cnxset may be none if no operation has been done since last commit |
0 | 880 |
# or rollback |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
881 |
cnxset = getattr(self._threaddata, 'cnxset', None) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
882 |
if cnxset is not None and (ignoremode or self.mode == 'read'): |
0 | 883 |
# even in read mode, we must release the current transaction |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
884 |
self._free_thread_cnxset(threading.currentThread(), cnxset) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
885 |
del self._threaddata.cnxset |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
886 |
self._threaddata.ctx_count -= 1 |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
887 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
888 |
def _touch(self): |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
889 |
"""update latest session usage timestamp and reset mode to read""" |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
890 |
self.timestamp = time() |
5046 | 891 |
self.local_perm_cache.clear() # XXX simply move in transaction_data, no? |
0 | 892 |
|
893 |
# shared data handling ################################################### |
|
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
894 |
|
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
895 |
def get_shared_data(self, key, default=None, pop=False, txdata=False): |
0 | 896 |
"""return value associated to `key` in session data""" |
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
897 |
if txdata: |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
898 |
data = self.transaction_data |
0 | 899 |
else: |
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
900 |
data = self.data |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
901 |
if pop: |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
902 |
return data.pop(key, default) |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
903 |
else: |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
904 |
return data.get(key, default) |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
905 |
|
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
906 |
def set_shared_data(self, key, value, txdata=False): |
0 | 907 |
"""set value associated to `key` in session data""" |
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
908 |
if txdata: |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
909 |
self.transaction_data[key] = value |
0 | 910 |
else: |
911 |
self.data[key] = value |
|
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
912 |
|
8367
fc59d2380c48
[service-api] Add unified service API on `_cw` attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8306
diff
changeset
|
913 |
# server-side service call ################################################# |
fc59d2380c48
[service-api] Add unified service API on `_cw` attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8306
diff
changeset
|
914 |
|
fc59d2380c48
[service-api] Add unified service API on `_cw` attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8306
diff
changeset
|
915 |
def call_service(self, regid, async=False, **kwargs): |
fc59d2380c48
[service-api] Add unified service API on `_cw` attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8306
diff
changeset
|
916 |
return self.repo.call_service(self.id, regid, async, **kwargs) |
fc59d2380c48
[service-api] Add unified service API on `_cw` attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8306
diff
changeset
|
917 |
|
fc59d2380c48
[service-api] Add unified service API on `_cw` attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8306
diff
changeset
|
918 |
|
0 | 919 |
# request interface ####################################################### |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
920 |
|
2855
1d9be3dffa94
[repo] more deprecation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2840
diff
changeset
|
921 |
@property |
1d9be3dffa94
[repo] more deprecation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2840
diff
changeset
|
922 |
def cursor(self): |
1d9be3dffa94
[repo] more deprecation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2840
diff
changeset
|
923 |
"""return a rql cursor""" |
1d9be3dffa94
[repo] more deprecation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2840
diff
changeset
|
924 |
return self |
1d9be3dffa94
[repo] more deprecation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2840
diff
changeset
|
925 |
|
0 | 926 |
def set_entity_cache(self, entity): |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
927 |
# XXX session level caching may be a pb with multiple repository |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
928 |
# instances, but 1. this is probably not the only one :$ and 2. it |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
929 |
# may be an acceptable risk. Anyway we could activate it or not |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
930 |
# according to a configuration option |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
931 |
try: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
932 |
self.transaction_data['ecache'].setdefault(entity.eid, entity) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
933 |
except KeyError: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
934 |
self.transaction_data['ecache'] = ecache = {} |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
935 |
ecache[entity.eid] = entity |
0 | 936 |
|
937 |
def entity_cache(self, eid): |
|
5014
96bb4e7e3348
[cleanup] useless try except
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4992
diff
changeset
|
938 |
return self.transaction_data['ecache'][eid] |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
939 |
|
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
940 |
def cached_entities(self): |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
941 |
return self.transaction_data.get('ecache', {}).values() |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
942 |
|
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
943 |
def drop_entity_cache(self, eid=None): |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
944 |
if eid is None: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
945 |
self.transaction_data.pop('ecache', None) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
946 |
else: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2630
diff
changeset
|
947 |
del self.transaction_data['ecache'][eid] |
0 | 948 |
|
949 |
def from_controller(self): |
|
950 |
"""return the id (string) of the controller issuing the request (no |
|
951 |
sense here, always return 'view') |
|
952 |
""" |
|
953 |
return 'view' |
|
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
954 |
|
0 | 955 |
def source_defs(self): |
956 |
return self.repo.source_defs() |
|
957 |
||
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
958 |
def describe(self, eid, asdict=False): |
0 | 959 |
"""return a tuple (type, sourceuri, extid) for the entity with id <eid>""" |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
960 |
metas = self.repo.type_and_source_from_eid(eid, self) |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
961 |
if asdict: |
8306
4da49700b06a
[config, undo] Fix undo-support option migration
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8265
diff
changeset
|
962 |
return dict(zip(('type', 'source', 'extid', 'asource'), metas)) |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
963 |
# XXX :-1 for cw compat, use asdict=True for full information |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
964 |
return metas[:-1] |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
965 |
|
0 | 966 |
# db-api like interface ################################################### |
967 |
||
968 |
def source_from_eid(self, eid): |
|
969 |
"""return the source where the entity with id <eid> is located""" |
|
970 |
return self.repo.source_from_eid(eid, self) |
|
971 |
||
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
972 |
def execute(self, rql, kwargs=None, eid_key=None, build_descr=True): |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
973 |
"""db-api like method directly linked to the querier execute method. |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
974 |
|
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
975 |
See :meth:`cubicweb.dbapi.Cursor.execute` documentation. |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
976 |
""" |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
977 |
if eid_key is not None: |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
978 |
warn('[3.8] eid_key is deprecated, you can safely remove this argument', |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
979 |
DeprecationWarning, stacklevel=2) |
5792
e13aa4786a72
[session] update session's timestamp in session.execute, so long running transactions are not erroneously closed by the repository
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5791
diff
changeset
|
980 |
self.timestamp = time() # update timestamp |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
981 |
rset = self._execute(self, rql, kwargs, build_descr) |
4850
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4845
diff
changeset
|
982 |
rset.req = self |
0 | 983 |
return rset |
984 |
||
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
985 |
def _clear_thread_data(self, free_cnxset=True): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
986 |
"""remove everything from the thread local storage, except connections set |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
987 |
which is explicitly removed by free_cnxset, and mode which is set anyway |
4704
a1ac5a453146
[session] fix memory leak: local thread data living in a thread that never finishes (eg, the main thread) may not be properly freed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4703
diff
changeset
|
988 |
by _touch |
a1ac5a453146
[session] fix memory leak: local thread data living in a thread that never finishes (eg, the main thread) may not be properly freed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4703
diff
changeset
|
989 |
""" |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
990 |
try: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
991 |
txstore = self.__threaddata.txdata |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
992 |
except AttributeError: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
993 |
pass |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
994 |
else: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
995 |
if free_cnxset: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
996 |
self.free_cnxset() |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
997 |
if txstore.ctx_count == 0: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
998 |
self._clear_thread_storage(txstore) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
999 |
else: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1000 |
self._clear_tx_storage(txstore) |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1001 |
else: |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1002 |
self._clear_tx_storage(txstore) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1003 |
|
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1004 |
def _clear_thread_storage(self, txstore): |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1005 |
self._tx_data.pop(txstore.transactionid, None) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1006 |
try: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1007 |
del self.__threaddata.txdata |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1008 |
except AttributeError: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1009 |
pass |
4704
a1ac5a453146
[session] fix memory leak: local thread data living in a thread that never finishes (eg, the main thread) may not be properly freed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4703
diff
changeset
|
1010 |
|
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1011 |
def _clear_tx_storage(self, txstore): |
8764
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
1012 |
txstore.clear() |
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
1013 |
for name in ('_rewriter', 'pruned_hooks_cache'): |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1014 |
try: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1015 |
delattr(txstore, name) |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1016 |
except AttributeError: |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7349
diff
changeset
|
1017 |
continue |
4704
a1ac5a453146
[session] fix memory leak: local thread data living in a thread that never finishes (eg, the main thread) may not be properly freed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4703
diff
changeset
|
1018 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1019 |
def commit(self, free_cnxset=True, reset_pool=None): |
0 | 1020 |
"""commit the current session's transaction""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1021 |
if reset_pool is not None: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1022 |
warn('[3.13] use free_cnxset argument instead for reset_pool', |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1023 |
DeprecationWarning, stacklevel=2) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1024 |
free_cnxset = reset_pool |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1025 |
if self.cnxset is None: |
0 | 1026 |
assert not self.pending_operations |
4704
a1ac5a453146
[session] fix memory leak: local thread data living in a thread that never finishes (eg, the main thread) may not be properly freed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4703
diff
changeset
|
1027 |
self._clear_thread_data() |
0 | 1028 |
self._touch() |
2200
25bb65dc4559
test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2190
diff
changeset
|
1029 |
self.debug('commit session %s done (no db activity)', self.id) |
0 | 1030 |
return |
6385
9f91d09ee5fa
[repo transaction] fix rollback behaviour as discussed on the mailing-list: instead of rollbacking automatically on Unauthorized/ValidationError, mark the transaction as uncommitable and disallow commiting
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6071
diff
changeset
|
1031 |
cstate = self.commit_state |
9f91d09ee5fa
[repo transaction] fix rollback behaviour as discussed on the mailing-list: instead of rollbacking automatically on Unauthorized/ValidationError, mark the transaction as uncommitable and disallow commiting
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6071
diff
changeset
|
1032 |
if cstate == 'uncommitable': |
9f91d09ee5fa
[repo transaction] fix rollback behaviour as discussed on the mailing-list: instead of rollbacking automatically on Unauthorized/ValidationError, mark the transaction as uncommitable and disallow commiting
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6071
diff
changeset
|
1033 |
raise QueryError('transaction must be rollbacked') |
9f91d09ee5fa
[repo transaction] fix rollback behaviour as discussed on the mailing-list: instead of rollbacking automatically on Unauthorized/ValidationError, mark the transaction as uncommitable and disallow commiting
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6071
diff
changeset
|
1034 |
if cstate is not None: |
0 | 1035 |
return |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1036 |
# on rollback, an operation should have the following state |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1037 |
# information: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1038 |
# - processed by the precommit/commit event or not |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1039 |
# - if processed, is it the failed operation |
8626
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1040 |
debug = server.DEBUG & server.DBG_OPS |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1041 |
try: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1042 |
# by default, operations are executed with security turned off |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1043 |
with security_enabled(self, False, False): |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1044 |
processed = [] |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1045 |
self.commit_state = 'precommit' |
8626
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1046 |
if debug: |
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1047 |
print self.commit_state, '*' * 20 |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1048 |
try: |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1049 |
while self.pending_operations: |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1050 |
operation = self.pending_operations.pop(0) |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1051 |
operation.processed = 'precommit' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1052 |
processed.append(operation) |
8626
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1053 |
if debug: |
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1054 |
print operation |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1055 |
operation.handle_event('precommit_event') |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1056 |
self.pending_operations[:] = processed |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1057 |
self.debug('precommit session %s done', self.id) |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1058 |
except BaseException: |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1059 |
# if error on [pre]commit: |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1060 |
# |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1061 |
# * set .failed = True on the operation causing the failure |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1062 |
# * call revert<event>_event on processed operations |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1063 |
# * call rollback_event on *all* operations |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1064 |
# |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1065 |
# that seems more natural than not calling rollback_event |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1066 |
# for processed operations, and allow generic rollback |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1067 |
# instead of having to implements rollback, revertprecommit |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1068 |
# and revertcommit, that will be enough in mont case. |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1069 |
operation.failed = True |
8626
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1070 |
if debug: |
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1071 |
print self.commit_state, '*' * 20 |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1072 |
for operation in reversed(processed): |
8626
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1073 |
if debug: |
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1074 |
print operation |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1075 |
try: |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1076 |
operation.handle_event('revertprecommit_event') |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1077 |
except BaseException: |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1078 |
self.critical('error while reverting precommit', |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1079 |
exc_info=True) |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1080 |
# XXX use slice notation since self.pending_operations is a |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1081 |
# read-only property. |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1082 |
self.pending_operations[:] = processed + self.pending_operations |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1083 |
self.rollback(free_cnxset) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1084 |
raise |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1085 |
self.cnxset.commit() |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1086 |
self.commit_state = 'postcommit' |
8626
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1087 |
if debug: |
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1088 |
print self.commit_state, '*' * 20 |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1089 |
while self.pending_operations: |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1090 |
operation = self.pending_operations.pop(0) |
8626
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1091 |
if debug: |
e2ba137b2bf9
[server] add debugging for Hooks & Operations (closes #2470048)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8596
diff
changeset
|
1092 |
print operation |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1093 |
operation.processed = 'postcommit' |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1094 |
try: |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1095 |
operation.handle_event('postcommit_event') |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1096 |
except BaseException: |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1097 |
self.critical('error while postcommit', |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1098 |
exc_info=sys.exc_info()) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6077
diff
changeset
|
1099 |
self.debug('postcommit session %s done', self.id) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1100 |
return self.transaction_uuid(set=False) |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1101 |
finally: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1102 |
self._touch() |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1103 |
if free_cnxset: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1104 |
self.free_cnxset(ignoremode=True) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1105 |
self._clear_thread_data(free_cnxset) |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1106 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1107 |
def rollback(self, free_cnxset=True, reset_pool=None): |
0 | 1108 |
"""rollback the current session's transaction""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1109 |
if reset_pool is not None: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1110 |
warn('[3.13] use free_cnxset argument instead for reset_pool', |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1111 |
DeprecationWarning, stacklevel=2) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1112 |
free_cnxset = reset_pool |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1113 |
# don't use self.cnxset, rollback may be called with _closed == True |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1114 |
cnxset = getattr(self._threaddata, 'cnxset', None) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1115 |
if cnxset is None: |
4704
a1ac5a453146
[session] fix memory leak: local thread data living in a thread that never finishes (eg, the main thread) may not be properly freed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4703
diff
changeset
|
1116 |
self._clear_thread_data() |
0 | 1117 |
self._touch() |
2200
25bb65dc4559
test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2190
diff
changeset
|
1118 |
self.debug('rollback session %s done (no db activity)', self.id) |
0 | 1119 |
return |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1120 |
try: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1121 |
# by default, operations are executed with security turned off |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1122 |
with security_enabled(self, False, False): |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1123 |
while self.pending_operations: |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1124 |
try: |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1125 |
operation = self.pending_operations.pop(0) |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1126 |
operation.handle_event('rollback_event') |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
1127 |
except BaseException: |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1128 |
self.critical('rollback error', exc_info=sys.exc_info()) |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1129 |
continue |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1130 |
cnxset.rollback() |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1131 |
self.debug('rollback for session %s done', self.id) |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1132 |
finally: |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1133 |
self._touch() |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1134 |
if free_cnxset: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1135 |
self.free_cnxset(ignoremode=True) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1136 |
self._clear_thread_data(free_cnxset) |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1137 |
|
0 | 1138 |
def close(self): |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1139 |
"""do not close connections set on session close, since they are shared now""" |
7340
9303fd71c2ee
[session] lock self._closed and session.close to avoid race conditions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
1140 |
with self._closed_lock: |
9303fd71c2ee
[session] lock self._closed and session.close to avoid race conditions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7330
diff
changeset
|
1141 |
self._closed = True |
1880
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1142 |
# copy since _threads_in_transaction maybe modified while waiting |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1143 |
for thread, cnxset in self._threads_in_transaction.copy(): |
1880
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1144 |
if thread is threading.currentThread(): |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1145 |
continue |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1146 |
self.info('waiting for thread %s', thread) |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1147 |
# do this loop/break instead of a simple join(10) in case thread is |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1148 |
# the main thread (in which case it will be removed from |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1149 |
# self._threads_in_transaction but still be alive...) |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1150 |
for i in xrange(10): |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1151 |
thread.join(1) |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1152 |
if not (thread.isAlive() and |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1153 |
(thread, cnxset) in self._threads_in_transaction): |
1880
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1154 |
break |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1155 |
else: |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1156 |
self.error('thread %s still alive after 10 seconds, will close ' |
293fe4b49e28
two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1660
diff
changeset
|
1157 |
'session anyway', thread) |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1158 |
self._free_thread_cnxset(thread, cnxset, force_close=True) |
0 | 1159 |
self.rollback() |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1160 |
del self.__threaddata |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5802
diff
changeset
|
1161 |
del self._tx_data |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1162 |
|
7054
c8f12ab250b7
Add a "closed" property on session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
1163 |
@property |
c8f12ab250b7
Add a "closed" property on session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
1164 |
def closed(self): |
c8f12ab250b7
Add a "closed" property on session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
1165 |
return not hasattr(self, '_tx_data') |
c8f12ab250b7
Add a "closed" property on session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6582
diff
changeset
|
1166 |
|
0 | 1167 |
# transaction data/operations management ################################## |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1168 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1169 |
@property |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1170 |
def transaction_data(self): |
8764
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
1171 |
return self._threaddata.transaction_data |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1172 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1173 |
@property |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1174 |
def pending_operations(self): |
8764
c4f022a6c7dd
[transaction] initialize transaction data and state related attribute.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8763
diff
changeset
|
1175 |
return self._threaddata.pending_operations |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1176 |
|
7387
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
1177 |
@property |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
1178 |
def pruned_hooks_cache(self): |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
1179 |
try: |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
1180 |
return self._threaddata.pruned_hooks_cache |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
1181 |
except AttributeError: |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
1182 |
self._threaddata.pruned_hooks_cache = {} |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
1183 |
return self._threaddata.pruned_hooks_cache |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7352
diff
changeset
|
1184 |
|
0 | 1185 |
def add_operation(self, operation, index=None): |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1186 |
"""add an operation""" |
4767 | 1187 |
if index is None: |
1188 |
self.pending_operations.append(operation) |
|
1189 |
else: |
|
0 | 1190 |
self.pending_operations.insert(index, operation) |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1191 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1192 |
# undo support ############################################################ |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1193 |
|
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
1194 |
def ertype_supports_undo(self, ertype): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8190
diff
changeset
|
1195 |
return self.undo_actions and ertype not in NO_UNDO_TYPES |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1196 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1197 |
def transaction_uuid(self, set=True): |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1198 |
try: |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1199 |
return self.transaction_data['tx_uuid'] |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1200 |
except KeyError: |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1201 |
if not set: |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1202 |
return |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1203 |
self.transaction_data['tx_uuid'] = uuid = uuid4().hex |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1204 |
self.repo.system_source.start_undoable_transaction(self, uuid) |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1205 |
return uuid |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1206 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1207 |
def transaction_inc_action_counter(self): |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1208 |
num = self.transaction_data.setdefault('tx_action_count', 0) + 1 |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1209 |
self.transaction_data['tx_action_count'] = num |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1210 |
return num |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1211 |
|
0 | 1212 |
# querier helpers ######################################################### |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1213 |
|
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1214 |
@property |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1215 |
def rql_rewriter(self): |
4704
a1ac5a453146
[session] fix memory leak: local thread data living in a thread that never finishes (eg, the main thread) may not be properly freed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4703
diff
changeset
|
1216 |
# in thread local storage since the rewriter isn't thread safe |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1217 |
try: |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1218 |
return self._threaddata._rewriter |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1219 |
except AttributeError: |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3198
diff
changeset
|
1220 |
self._threaddata._rewriter = RQLRewriter(self) |
2100
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1221 |
return self._threaddata._rewriter |
89b825cdec74
simplify transaction data api, reorganize code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
1222 |
|
2855
1d9be3dffa94
[repo] more deprecation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2840
diff
changeset
|
1223 |
# deprecated ############################################################### |
1d9be3dffa94
[repo] more deprecation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2840
diff
changeset
|
1224 |
|
7502
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
1225 |
@deprecated('[3.13] use getattr(session.rtype_eids_rdef(rtype, eidfrom, eidto), prop)') |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
1226 |
def schema_rproperty(self, rtype, eidfrom, eidto, rprop): |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
1227 |
return getattr(self.rtype_eids_rdef(rtype, eidfrom, eidto), rprop) |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
1228 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1229 |
@property |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1230 |
@deprecated("[3.13] use .cnxset attribute instead of .pool") |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1231 |
def pool(self): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1232 |
return self.cnxset |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1233 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1234 |
@deprecated("[3.13] use .set_cnxset() method instead of .set_pool()") |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1235 |
def set_pool(self): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1236 |
return self.set_cnxset() |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1237 |
|
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1238 |
@deprecated("[3.13] use .free_cnxset() method instead of .reset_pool()") |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1239 |
def reset_pool(self): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1240 |
return self.free_cnxset() |
7502
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7500
diff
changeset
|
1241 |
|
4987
ec93dd82c83f
[repo] fix warning message and implementation of bw compat unsafe_execute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4924
diff
changeset
|
1242 |
@deprecated("[3.7] execute is now unsafe by default in hooks/operation. You" |
5130
929984f017e6
nicer warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5108
diff
changeset
|
1243 |
" can also control security with the security_enabled context " |
929984f017e6
nicer warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5108
diff
changeset
|
1244 |
"manager") |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1245 |
def unsafe_execute(self, rql, kwargs=None, eid_key=None, build_descr=True, |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1246 |
propagate=False): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1247 |
"""like .execute but with security checking disabled (this method is |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1248 |
internal to the server, it's not part of the db-api) |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1249 |
""" |
4987
ec93dd82c83f
[repo] fix warning message and implementation of bw compat unsafe_execute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4924
diff
changeset
|
1250 |
with security_enabled(self, read=False, write=False): |
ec93dd82c83f
[repo] fix warning message and implementation of bw compat unsafe_execute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4924
diff
changeset
|
1251 |
return self.execute(rql, kwargs, eid_key, build_descr) |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1252 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1253 |
@property |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1254 |
@deprecated("[3.7] is_super_session is deprecated, test " |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1255 |
"session.read_security and or session.write_security") |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1256 |
def is_super_session(self): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1257 |
return not self.read_security or not self.write_security |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1258 |
|
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1259 |
@deprecated("[3.7] session is actual session") |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1260 |
def actual_session(self): |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1261 |
"""return the original parent session if any, else self""" |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1262 |
return self |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1263 |
|
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7054
diff
changeset
|
1264 |
# these are overridden by set_log_methods below |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7054
diff
changeset
|
1265 |
# only defining here to prevent pylint from complaining |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7054
diff
changeset
|
1266 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7054
diff
changeset
|
1267 |
|
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1268 |
|
0 | 1269 |
class InternalSession(Session): |
1270 |
"""special session created internaly by the repository""" |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1271 |
is_internal_session = True |
5193
c9671feff5e2
[session] no way for queries from an InternalSession to be a dbapi query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5130
diff
changeset
|
1272 |
running_dbapi_query = False |
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1273 |
|
7706
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7665
diff
changeset
|
1274 |
def __init__(self, repo, cnxprops=None, safe=False): |
2891
60afb9705035
[session] temporary fix, need .req on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
1275 |
super(InternalSession, self).__init__(InternalManager(), repo, cnxprops, |
0 | 1276 |
_id='internal') |
6071
c7a9e25153c2
[session] should be _cw, not req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6028
diff
changeset
|
1277 |
self.user._cw = self # XXX remove when "vreg = user._cw.vreg" hack in entity.py is gone |
7706
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7665
diff
changeset
|
1278 |
if not safe: |
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7665
diff
changeset
|
1279 |
self.disable_hook_categories('integrity') |
0 | 1280 |
|
8433
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8367
diff
changeset
|
1281 |
def __enter__(self): |
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8367
diff
changeset
|
1282 |
return self |
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8367
diff
changeset
|
1283 |
|
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8367
diff
changeset
|
1284 |
def __exit__(self, exctype, excvalue, tb): |
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8367
diff
changeset
|
1285 |
self.close() |
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8367
diff
changeset
|
1286 |
|
5906
d40ced753291
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5826
diff
changeset
|
1287 |
@property |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1288 |
def cnxset(self): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1289 |
"""connections set, set according to transaction mode for each query""" |
5906
d40ced753291
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5826
diff
changeset
|
1290 |
if self.repo.shutting_down: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1291 |
self.free_cnxset(True) |
7573
c8f8762c986d
[repo, looping task] raise a custom exception when repository is shuting down, avoid looping task to be restarted in such case. Closes #1021276
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7526
diff
changeset
|
1292 |
raise ShuttingDown('repository is shutting down') |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
1293 |
return getattr(self._threaddata, 'cnxset', None) |
5906
d40ced753291
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5826
diff
changeset
|
1294 |
|
0 | 1295 |
|
1296 |
class InternalManager(object): |
|
1297 |
"""a manager user with all access rights used internally for task such as |
|
1298 |
bootstrapping the repository or creating regular users according to |
|
1299 |
repository content |
|
1300 |
""" |
|
1301 |
def __init__(self): |
|
1302 |
self.eid = -1 |
|
1303 |
self.login = u'__internal_manager__' |
|
1304 |
self.properties = {} |
|
1305 |
||
1306 |
def matching_groups(self, groups): |
|
1307 |
return 1 |
|
1308 |
||
1309 |
def is_in_group(self, group): |
|
1310 |
return True |
|
1311 |
||
1312 |
def owns(self, eid): |
|
1313 |
return True |
|
1660
d1030dd9730b
delete-trailing-whitespaces, missing import
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
1314 |
|
0 | 1315 |
def property_value(self, key): |
1316 |
if key == 'ui.language': |
|
1317 |
return 'en' |
|
1318 |
return None |
|
1319 |
||
8563
d28ccecb7bf5
mock ``CWUser.prefered_language()`` on InternalManager objects.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8562
diff
changeset
|
1320 |
def prefered_language(self, language=None): |
d28ccecb7bf5
mock ``CWUser.prefered_language()`` on InternalManager objects.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8562
diff
changeset
|
1321 |
# mock CWUser.prefered_language, mainly for testing purpose |
d28ccecb7bf5
mock ``CWUser.prefered_language()`` on InternalManager objects.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8562
diff
changeset
|
1322 |
return self.property_value('ui.language') |
0 | 1323 |
|
8579
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1324 |
# CWUser compat for notification ########################################### |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1325 |
|
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1326 |
def name(self): |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1327 |
return 'cubicweb' |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1328 |
|
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1329 |
class _IEmailable: |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1330 |
@staticmethod |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1331 |
def get_email(): |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1332 |
return '' |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1333 |
|
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1334 |
def cw_adapt_to(self, iface): |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1335 |
if iface == 'IEmailable': |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1336 |
return self._IEmailable |
c4673bc11053
[req / session] drop is_internal_session (buggy) compat on base request by implementing necessary methods on internal manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8563
diff
changeset
|
1337 |
return None |
0 | 1338 |
|
1339 |
from logging import getLogger |
|
1340 |
from cubicweb import set_log_methods |
|
1341 |
set_log_methods(Session, getLogger('cubicweb.session')) |