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
5941598b
Commit
5941598b
authored
Mar 06, 2014
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make pure-python Persistent only call jar.setstate() when it is a ghost instead of every time.
parent
6e813bf4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
7 deletions
+25
-7
CHANGES.rst
CHANGES.rst
+5
-0
persistent/persistence.py
persistent/persistence.py
+7
-7
persistent/tests/test_persistence.py
persistent/tests/test_persistence.py
+13
-0
No files found.
CHANGES.rst
View file @
5941598b
...
...
@@ -4,6 +4,11 @@
4.0.8 (Unreleased)
------------------
- In pure-Python ``Persistent``, calling ``_p_activate`` no longer
corrupts the state of a non-ghost object, and it doesn't throw
``POSKeyError`` if called on an object that has never been committed.
(PR #9)
- In pure-Python ``Persistent``, avoid calling a subclass's ``__setattr__``
at instance creation time. (PR #8)
...
...
persistent/persistence.py
View file @
5941598b
...
...
@@ -330,14 +330,14 @@ class Persistent(object):
""" See IPersistent.
"""
before
=
self
.
__flags
if
self
.
__flags
is
None
:
if
self
.
__flags
is
None
or
self
.
_p_state
<
0
:
# Only do this if we're a ghost
self
.
__flags
=
0
if
self
.
__jar
is
not
None
and
self
.
__oid
is
not
None
:
try
:
self
.
__jar
.
setstate
(
self
)
except
:
self
.
__flags
=
before
raise
if
self
.
__jar
is
not
None
and
self
.
__oid
is
not
None
:
try
:
self
.
__jar
.
setstate
(
self
)
except
:
self
.
__flags
=
before
raise
def
_p_deactivate
(
self
):
""" See IPersistent.
...
...
persistent/tests/test_persistence.py
View file @
5941598b
...
...
@@ -978,6 +978,19 @@ class _Persistent_Base(object):
inst
.
_p_activate
()
# noop from 'saved' state
self
.
assertEqual
(
inst
.
_p_status
,
'saved'
)
def
test__p_activate_only_sets_state_once
(
self
):
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
# No matter how many times we call _p_activate, it
# only sets state once, the first time
inst
.
_p_invalidate
()
# make it a ghost
self
.
assertEqual
(
list
(
jar
.
_loaded
),
[])
inst
.
_p_activate
()
self
.
assertEqual
(
list
(
jar
.
_loaded
),
[
OID
])
inst
.
_p_activate
()
self
.
assertEqual
(
list
(
jar
.
_loaded
),
[
OID
])
def
test__p_deactivate_from_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_deactivate
()
...
...
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