Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
8dbdceec
Commit
8dbdceec
authored
Nov 17, 2011
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the last fix and fixed the test that failed to show the need for
the fix fix.
parent
0cd1074f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
12 deletions
+32
-12
src/ZODB/ConflictResolution.py
src/ZODB/ConflictResolution.py
+15
-5
src/ZODB/tests/testconflictresolution.py
src/ZODB/tests/testconflictresolution.py
+17
-7
No files found.
src/ZODB/ConflictResolution.py
View file @
8dbdceec
...
@@ -29,7 +29,7 @@ ResolvedSerial = 'rs'
...
@@ -29,7 +29,7 @@ ResolvedSerial = 'rs'
class
BadClassName
(
Exception
):
class
BadClassName
(
Exception
):
pass
pass
class
BadClass
:
class
BadClass
(
object
)
:
def
__init__
(
self
,
*
args
):
def
__init__
(
self
,
*
args
):
self
.
args
=
args
self
.
args
=
args
...
@@ -123,13 +123,13 @@ class PersistentReference(object):
...
@@ -123,13 +123,13 @@ class PersistentReference(object):
self
.
data
=
data
self
.
data
=
data
# see serialize.py, ObjectReader._persistent_load
# see serialize.py, ObjectReader._persistent_load
if
isinstance
(
data
,
tuple
):
if
isinstance
(
data
,
tuple
):
self
.
oid
,
self
.
klass
=
data
self
.
oid
,
klass
=
data
if
isinstance
(
self
.
klass
,
BadClass
):
if
isinstance
(
klass
,
BadClass
):
# We can't use the BadClass directly because, if
# We can't use the BadClass directly because, if
# resolution succeeds, there's no good way to pickle
# resolution succeeds, there's no good way to pickle
# it. Fortunately, a class reference in a persistent
# it. Fortunately, a class reference in a persistent
# reference is allowed to be a module+name tuple.
# reference is allowed to be a module+name tuple.
self
.
klass
=
self
.
klass
.
args
self
.
data
=
self
.
oid
,
klass
.
args
elif
isinstance
(
data
,
str
):
elif
isinstance
(
data
,
str
):
self
.
oid
=
data
self
.
oid
=
data
else
:
# a list
else
:
# a list
...
@@ -140,7 +140,7 @@ class PersistentReference(object):
...
@@ -140,7 +140,7 @@ class PersistentReference(object):
# or persistent weakref: (oid, database_name)
# or persistent weakref: (oid, database_name)
# else it is a weakref: reference_type
# else it is a weakref: reference_type
if
reference_type
==
'm'
:
if
reference_type
==
'm'
:
self
.
database_name
,
self
.
oid
,
self
.
klass
=
data
[
1
]
self
.
database_name
,
self
.
oid
,
_
=
data
[
1
]
elif
reference_type
==
'n'
:
elif
reference_type
==
'n'
:
self
.
database_name
,
self
.
oid
=
data
[
1
]
self
.
database_name
,
self
.
oid
=
data
[
1
]
elif
reference_type
==
'w'
:
elif
reference_type
==
'w'
:
...
@@ -173,6 +173,16 @@ class PersistentReference(object):
...
@@ -173,6 +173,16 @@ class PersistentReference(object):
def
__getstate__
(
self
):
def
__getstate__
(
self
):
raise
PicklingError
(
"Can't pickle PersistentReference"
)
raise
PicklingError
(
"Can't pickle PersistentReference"
)
@
property
def
klass
(
self
):
# for tests
data
=
self
.
data
if
isinstance
(
data
,
tuple
):
return
data
[
1
]
elif
isinstance
(
data
,
list
)
and
data
[
0
]
==
'm'
:
return
data
[
1
][
2
]
class
PersistentReferenceFactory
:
class
PersistentReferenceFactory
:
data
=
None
data
=
None
...
...
src/ZODB/tests/testconflictresolution.py
View file @
8dbdceec
...
@@ -158,6 +158,9 @@ def resolve_even_when_referenced_classes_are_absent():
...
@@ -158,6 +158,9 @@ def resolve_even_when_referenced_classes_are_absent():
We often want to be able to resolve even when there are pesistent
We often want to be able to resolve even when there are pesistent
references to classes that can't be imported.
references to classes that can't be imported.
>>> class P(persistent.Persistent):
... pass
>>> db = ZODB.DB('t.fs') # FileStorage!
>>> db = ZODB.DB('t.fs') # FileStorage!
>>> storage = db.storage
>>> storage = db.storage
>>> conn = db.open()
>>> conn = db.open()
...
@@ -166,20 +169,19 @@ references to classes that can't be imported.
...
@@ -166,20 +169,19 @@ references to classes that can't be imported.
>>> oid = conn.root.x._p_oid
>>> oid = conn.root.x._p_oid
>>> serial = conn.root.x._p_serial
>>> serial = conn.root.x._p_serial
>>> class P(persistent.Persistent):
>>> conn.root.x.a = P()
... pass
>>> conn.root.x.a = a = P()
>>> transaction.commit()
>>> transaction.commit()
>>> aid = conn.root.x.a._p_oid
>>> serial1 = conn.root.x._p_serial
>>> serial1 = conn.root.x._p_serial
>>> del conn.root.x.a
>>> del conn.root.x.a
>>> conn.root.x.b =
b =
P()
>>> conn.root.x.b = P()
>>> transaction.commit()
>>> transaction.commit()
>>> serial2 = conn.root.x._p_serial
>>> serial2 = conn.root.x._p_serial
Bwahaha:
Bwahaha:
>>> P_aside = P
>>> del P
>>> del P
Now, even though we can't import P, we can still resolve the conflict:
Now, even though we can't import P, we can still resolve the conflict:
...
@@ -187,10 +189,18 @@ Now, even though we can't import P, we can still resolve the conflict:
...
@@ -187,10 +189,18 @@ Now, even though we can't import P, we can still resolve the conflict:
>>> p = storage.tryToResolveConflict(
>>> p = storage.tryToResolveConflict(
... oid, serial1, serial, storage.loadSerial(oid, serial2))
... oid, serial1, serial, storage.loadSerial(oid, serial2))
>>> p = conn._reader.getState(p)
And load the pickle:
>>> sorted(p), p['a'] is a, p['b'] is b
>>> conn2 = db.open()
>>> P = P_aside
>>> p = conn2._reader.getState(p)
>>> sorted(p), p['a'] is conn2.get(aid), p['b'] is conn2.root.x.b
(['a', 'b'], True, True)
(['a', 'b'], True, True)
>>> isinstance(p['a'], P) and isinstance(p['b'], P)
True
Oooooof course, this won't work if the subobjects aren't persistent:
Oooooof course, this won't work if the subobjects aren't persistent:
>>> class NP:
>>> class NP:
...
...
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