Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
533a4cfa
Commit
533a4cfa
authored
Nov 20, 2020
by
Kirill Smelkov
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X onResyncCallback for ZODB4
parent
1c3b7750
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
12 deletions
+30
-12
lib/tests/test_zodb.py
lib/tests/test_zodb.py
+1
-1
lib/zodb.py
lib/zodb.py
+29
-11
No files found.
lib/tests/test_zodb.py
View file @
533a4cfa
...
@@ -308,7 +308,7 @@ def test_zconn_at():
...
@@ -308,7 +308,7 @@ def test_zconn_at():
# verify that ZODB.Connection.onResyncCallback works
# verify that ZODB.Connection.onResyncCallback works
@
xfail
(
zmajor
<
5
,
reason
=
"ZODB.Connection.onResyncCallback is TODO for ZODB4 and
ZODB3"
)
@
xfail
(
zmajor
<
4
,
reason
=
"ZODB.Connection.onResyncCallback is TODO for
ZODB3"
)
@
func
@
func
def
test_zodb_onresync
():
def
test_zodb_onresync
():
stor
=
testdb
.
getZODBStorage
()
stor
=
testdb
.
getZODBStorage
()
...
...
lib/zodb.py
View file @
533a4cfa
...
@@ -260,8 +260,8 @@ ZODB.Connection.Connection.open = Connection_open
...
@@ -260,8 +260,8 @@ ZODB.Connection.Connection.open = Connection_open
# patch for ZODB.Connection to support callback on after database view is changed
# patch for ZODB.Connection to support callback on after database view is changed
ZODB
.
Connection
.
Connection
.
_onResyncCallbacks
=
None
ZODB
.
Connection
.
Connection
.
_onResyncCallbacks
=
None
def
Connection_onResyncCallback
(
self
,
f
):
def
Connection_onResyncCallback
(
self
,
f
):
if
zmajor
<=
4
:
if
zmajor
<=
3
:
raise
AssertionError
(
"onResyncCallback: TODO: add support for ZODB3
4
"
)
raise
AssertionError
(
"onResyncCallback: TODO: add support for ZODB3"
)
if
self
.
_onResyncCallbacks
is
None
:
if
self
.
_onResyncCallbacks
is
None
:
# NOTE WeakSet does not work for bound methods - they are always created
# NOTE WeakSet does not work for bound methods - they are always created
# anew for each obj.method access, and thus will go away almost immediately
# anew for each obj.method access, and thus will go away almost immediately
...
@@ -271,12 +271,7 @@ def Connection_onResyncCallback(self, f):
...
@@ -271,12 +271,7 @@ def Connection_onResyncCallback(self, f):
assert
not
hasattr
(
ZODB
.
Connection
.
Connection
,
'onResyncCallback'
)
assert
not
hasattr
(
ZODB
.
Connection
.
Connection
,
'onResyncCallback'
)
ZODB
.
Connection
.
Connection
.
onResyncCallback
=
Connection_onResyncCallback
ZODB
.
Connection
.
Connection
.
onResyncCallback
=
Connection_onResyncCallback
# ZODB5: hook into Connection.newTransaction
def
Connection__callResyncCallbacks
(
self
):
if
zmajor
>=
5
:
_orig_Connection_newTransaction
=
ZODB
.
Connection
.
Connection
.
newTransaction
def
_ZConnection_newTransaction
(
self
,
transaction
,
sync
=
True
):
_orig_Connection_newTransaction
(
self
,
transaction
,
sync
)
# FIXME method name hardcoded. Better not do it and allow f to be general
# FIXME method name hardcoded. Better not do it and allow f to be general
# callable, but that does not work with bound method - see above.
# callable, but that does not work with bound method - see above.
# ( Something like WeakMethod from py3 could help )
# ( Something like WeakMethod from py3 could help )
...
@@ -284,12 +279,35 @@ if zmajor >= 5:
...
@@ -284,12 +279,35 @@ if zmajor >= 5:
for
f
in
self
.
_onResyncCallbacks
:
for
f
in
self
.
_onResyncCallbacks
:
f
.
on_connection_resync
()
f
.
on_connection_resync
()
assert
not
hasattr
(
ZODB
.
Connection
.
Connection
,
'_callResyncCallbacks'
)
ZODB
.
Connection
.
Connection
.
_callResyncCallbacks
=
Connection__callResyncCallbacks
# ZODB5: hook into Connection.newTransaction
if
zmajor
>=
5
:
_orig_Connection_newTransaction
=
ZODB
.
Connection
.
Connection
.
newTransaction
def
_ZConnection_newTransaction
(
self
,
transaction
,
sync
=
True
):
_orig_Connection_newTransaction
(
self
,
transaction
,
sync
)
self
.
_callResyncCallbacks
()
ZODB
.
Connection
.
Connection
.
newTransaction
=
_ZConnection_newTransaction
ZODB
.
Connection
.
Connection
.
newTransaction
=
_ZConnection_newTransaction
# ZODB4: hook into Connection._
storage_sync
# ZODB4: hook into Connection._
flush_invalidations and ._resetCache
elif
zmajor
==
4
:
elif
zmajor
==
4
:
pass
# raises in onResyncCallback
# ._flush_invalidations is called by both Connection.open and Connection._storage_sync
# however Connection.open might call ._resetCache instead if global reset is requested
_orig_Connection__flush_invalidations
=
ZODB
.
Connection
.
Connection
.
_flush_invalidations
_orig_Connection__resetCache
=
ZODB
.
Connection
.
Connection
.
_resetCache
def
_ZConnection__flush_invalidations
(
self
):
_orig_Connection__flush_invalidations
(
self
)
self
.
_callResyncCallbacks
()
def
_ZConnection__resetCache
(
self
):
_orig_Connection__resetCache
(
self
)
self
.
_callResyncCallbacks
()
ZODB
.
Connection
.
Connection
.
_flush_invalidations
=
_ZConnection__flush_invalidations
ZODB
.
Connection
.
Connection
.
_resetCache
=
_ZConnection__resetCache
# ZODB3: TODO
# ZODB3: TODO
...
...
Kirill Smelkov
@kirr
mentioned in commit
ceadfcc7
·
Oct 28, 2021
mentioned in commit
ceadfcc7
mentioned in commit ceadfcc768fccef6c064d3391f97f74c94f6fe55
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment