Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
persistent
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
persistent
Commits
cf576871
Commit
cf576871
authored
Feb 24, 2014
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make deleting the _p_jar of a pure-Python persistent object work like the C version.
parent
2fa92003
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
1 deletion
+40
-1
CHANGES.rst
CHANGES.rst
+6
-0
persistent/persistence.py
persistent/persistence.py
+10
-1
persistent/tests/test_persistence.py
persistent/tests/test_persistence.py
+24
-0
No files found.
CHANGES.rst
View file @
cf576871
``persistent`` Changelog
``persistent`` Changelog
========================
========================
4.0.8 (Unreleased)
------------------
- Make it possible to delete the ``_p_jar`` of a pure-Python
``Persistent`` object (fixes aborting a ZODB Connection that
has added objects).
4.0.7 (2014-02-20)
4.0.7 (2014-02-20)
------------------
------------------
...
...
persistent/persistence.py
View file @
cf576871
...
@@ -72,7 +72,16 @@ class Persistent(object):
...
@@ -72,7 +72,16 @@ class Persistent(object):
self
.
__jar
=
value
self
.
__jar
=
value
self
.
__flags
=
0
self
.
__flags
=
0
_p_jar
=
property
(
_get_jar
,
_set_jar
)
def
_del_jar
(
self
):
jar
=
self
.
__jar
oid
=
self
.
__oid
if
jar
is
not
None
:
if
oid
and
jar
.
_cache
.
get
(
oid
):
raise
ValueError
(
"can't delete _p_jar of cached object"
)
self
.
__setattr__
(
'_Persistent__jar'
,
None
)
self
.
__flags
=
None
_p_jar
=
property
(
_get_jar
,
_set_jar
,
_del_jar
)
# _p_oid: see IPersistent.
# _p_oid: see IPersistent.
def
_get_oid
(
self
):
def
_get_oid
(
self
):
...
...
persistent/tests/test_persistence.py
View file @
cf576871
...
@@ -86,6 +86,24 @@ class _Persistent_Base(object):
...
@@ -86,6 +86,24 @@ class _Persistent_Base(object):
self
.
assertEqual
(
inst
.
_p_sticky
,
False
)
self
.
assertEqual
(
inst
.
_p_sticky
,
False
)
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test_cannot_del_jar_while_in_cache
(
self
):
inst
,
_
,
OID
=
self
.
_makeOneWithJar
()
def
_test
():
del
inst
.
_p_jar
self
.
assertRaises
(
ValueError
,
_test
)
def
test_del_jar_oid_like_ZODB_abort
(
self
):
# When a ZODB connection aborts,
# it removes registered objects from the cache,
# deletes their jar, deletes their OID
# and finally sets p_changed to false
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
del
jar
.
_cache
[
OID
]
del
inst
.
_p_jar
self
.
assertEqual
(
inst
.
_p_jar
,
None
)
del
inst
.
_p_oid
self
.
assertEqual
(
inst
.
_p_oid
,
None
)
def
test_assign_p_jar_w_new_jar
(
self
):
def
test_assign_p_jar_w_new_jar
(
self
):
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
new_jar
=
self
.
_makeJar
()
new_jar
=
self
.
_makeJar
()
...
@@ -1314,11 +1332,17 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
...
@@ -1314,11 +1332,17 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
def
__init__
(
self
,
jar
):
def
__init__
(
self
,
jar
):
self
.
_jar
=
jar
self
.
_jar
=
jar
self
.
_mru
=
[]
self
.
_mru
=
[]
self
.
_data
=
{}
def
mru
(
self
,
oid
):
def
mru
(
self
,
oid
):
self
.
_mru
.
append
(
oid
)
self
.
_mru
.
append
(
oid
)
def
new_ghost
(
self
,
oid
,
obj
):
def
new_ghost
(
self
,
oid
,
obj
):
obj
.
_p_jar
=
self
.
_jar
obj
.
_p_jar
=
self
.
_jar
obj
.
_p_oid
=
oid
obj
.
_p_oid
=
oid
self
.
_data
[
oid
]
=
obj
def
get
(
self
,
oid
):
return
self
.
_data
.
get
(
oid
)
def
__delitem__
(
self
,
oid
):
del
self
.
_data
[
oid
]
return
_Cache
(
jar
)
return
_Cache
(
jar
)
...
...
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