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
b0897986
Commit
b0897986
authored
Feb 24, 2014
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make deleting '_p_oid' in Python Persistent work like C too.
parent
cf576871
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
13 deletions
+22
-13
CHANGES.rst
CHANGES.rst
+3
-3
persistent/persistence.py
persistent/persistence.py
+5
-2
persistent/tests/test_persistence.py
persistent/tests/test_persistence.py
+14
-8
No files found.
CHANGES.rst
View file @
b0897986
...
@@ -4,9 +4,9 @@
...
@@ -4,9 +4,9 @@
4.0.8 (Unreleased)
4.0.8 (Unreleased)
------------------
------------------
- Make it possible to delete
the ``_p_jar
`` of a pure-Python
- Make it possible to delete
``_p_jar`` / ``_p_oid
`` of a pure-Python
``Persistent`` object
(fixes aborting a ZODB Connection that
``Persistent`` object
which has been removed from the jar's cache
has added objects).
(fixes aborting a ZODB Connection that has added objects). (PR #7)
4.0.7 (2014-02-20)
4.0.7 (2014-02-20)
------------------
------------------
...
...
persistent/persistence.py
View file @
b0897986
...
@@ -98,8 +98,11 @@ class Persistent(object):
...
@@ -98,8 +98,11 @@ class Persistent(object):
self
.
__oid
=
value
self
.
__oid
=
value
def
_del_oid
(
self
):
def
_del_oid
(
self
):
if
self
.
__jar
is
not
None
:
jar
=
self
.
__jar
raise
ValueError
(
'Cannot delete OID once assigned to a jar'
)
oid
=
self
.
__oid
if
jar
is
not
None
:
if
oid
and
jar
.
_cache
.
get
(
oid
):
raise
ValueError
(
'Cannot delete _p_oid of cached object'
)
self
.
__oid
=
None
self
.
__oid
=
None
_p_oid
=
property
(
_get_oid
,
_set_oid
,
_del_oid
)
_p_oid
=
property
(
_get_oid
,
_set_oid
,
_del_oid
)
...
...
persistent/tests/test_persistence.py
View file @
b0897986
...
@@ -86,23 +86,20 @@ class _Persistent_Base(object):
...
@@ -86,23 +86,20 @@ 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
):
def
test_del_jar_while_in_cache
(
self
):
inst
,
_
,
OID
=
self
.
_makeOneWithJar
()
inst
,
_
,
OID
=
self
.
_makeOneWithJar
()
def
_test
():
def
_test
():
del
inst
.
_p_jar
del
inst
.
_p_jar
self
.
assertRaises
(
ValueError
,
_test
)
self
.
assertRaises
(
ValueError
,
_test
)
def
test_del_jar_oid_like_ZODB_abort
(
self
):
def
test_del_jar_like_ZODB_abort
(
self
):
# When a ZODB connection aborts,
# When a ZODB connection aborts, it removes registered objects from
# it removes registered objects from the cache,
# the cache, deletes their jar, deletes their OID, and finally sets
# deletes their jar, deletes their OID
# p_changed to false
# and finally sets p_changed to false
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
del
jar
.
_cache
[
OID
]
del
jar
.
_cache
[
OID
]
del
inst
.
_p_jar
del
inst
.
_p_jar
self
.
assertEqual
(
inst
.
_p_jar
,
None
)
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
()
...
@@ -164,6 +161,15 @@ class _Persistent_Base(object):
...
@@ -164,6 +161,15 @@ class _Persistent_Base(object):
del
inst
.
_p_oid
del
inst
.
_p_oid
self
.
assertRaises
(
ValueError
,
_test
)
self
.
assertRaises
(
ValueError
,
_test
)
def
test_del_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_oid
self
.
assertEqual
(
inst
.
_p_oid
,
None
)
def
test_assign_p_serial_w_invalid_type
(
self
):
def
test_assign_p_serial_w_invalid_type
(
self
):
inst
=
self
.
_makeOne
()
inst
=
self
.
_makeOne
()
def
_test
():
def
_test
():
...
...
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