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
Joshua
zodb
Commits
17b317b3
Commit
17b317b3
authored
Sep 13, 2005
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When obj is a ghost, "obj._p_changed = some_true_value"
now activates obj.
parent
0fefaa89
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
17 deletions
+56
-17
NEWS.txt
NEWS.txt
+11
-0
src/persistent/cPersistence.c
src/persistent/cPersistence.c
+17
-2
src/persistent/interfaces.py
src/persistent/interfaces.py
+15
-6
src/persistent/tests/persistent.txt
src/persistent/tests/persistent.txt
+13
-9
No files found.
NEWS.txt
View file @
17b317b3
...
...
@@ -10,6 +10,17 @@ Zope3 development). These are the dates of the internal releases:
- 3.6a2 06-Sep-2005
- 3.6a1 04-Sep-2005
Persistent
----------
- (3.6a4) ZODB 3.6 introduces a change to the basic behavior of Persistent
objects in a particular end case. Before ZODB 3.6, setting
``obj._p_changed`` to a true value when ``obj`` was a ghost was ignored:
``obj`` remained a ghost, and getting ``obj._p_changed`` continued to
return ``None``. Starting with ZODB 3.6, ``obj`` is activated instead
(unghostified), and its state is changed from the ghost state to the
changed state. The new behavior is less surprising and more robust.
Commit hooks
------------
...
...
src/persistent/cPersistence.c
View file @
17b317b3
...
...
@@ -832,7 +832,9 @@ Per_get_changed(cPersistentObject *self)
static
int
Per_set_changed
(
cPersistentObject
*
self
,
PyObject
*
v
)
{
int
deactivate
=
0
,
true
;
int
deactivate
=
0
;
int
true
;
if
(
!
v
)
{
/* delattr is used to invalidate an object even if it has changed. */
if
(
self
->
state
!=
cPersistent_GHOST_STATE
)
...
...
@@ -868,12 +870,25 @@ Per_set_changed(cPersistentObject *self, PyObject *v)
Py_DECREF
(
meth
);
return
0
;
}
/* !deactivate. If passed a true argument, mark self as changed (starting
* with ZODB 3.6, that includes activating the object if it's a ghost).
* If passed a false argument, and the object isn't a ghost, set the
* state as up-to-date.
*/
true
=
PyObject_IsTrue
(
v
);
if
(
true
==
-
1
)
return
-
1
;
else
if
(
true
)
if
(
true
)
{
if
(
self
->
state
<
0
)
{
if
(
unghostify
(
self
)
<
0
)
return
-
1
;
}
return
changed
(
self
);
}
/* We were passed a false, non-None argument. If we're not a ghost,
* mark self as up-to-date.
*/
if
(
self
->
state
>=
0
)
self
->
state
=
cPersistent_UPTODATE_STATE
;
return
0
;
...
...
src/persistent/interfaces.py
View file @
17b317b3
...
...
@@ -71,7 +71,7 @@ class IPersistent(Interface):
In all the above, _p_oid (the persistent object id) is set when
_p_jar first gets set.
The following state trans
ac
tions are possible:
The following state trans
i
tions are possible:
- Unsaved -> Saved
...
...
@@ -82,13 +82,18 @@ class IPersistent(Interface):
- Saved -> Changed
Sticky -> Changed
Ghost -> Changed
This transition occurs when someone sets an attribute or sets
_p_changed to a true value on a saved
or sticky object. When the
transition occurs, the persistent object is required to call the
_p_changed to a true value on a saved
, sticky or ghost object. When
t
he t
ransition occurs, the persistent object is required to call the
register() method on its data manager, passing itself as the
only argument.
Prior to ZODB 3.6, setting _p_changed to a true value on a ghost object
was ignored (the object remained a ghost, and getting its _p_changed
attribute continued to return None).
- Saved -> Sticky
This transition occurs when C code marks the object as sticky to
...
...
@@ -166,7 +171,7 @@ class IPersistent(Interface):
"""
)
_p_changed
=
Attribute
(
"""The persistent state of the object
"""The persistent state of the object
.
This is one of:
...
...
@@ -181,6 +186,10 @@ class IPersistent(Interface):
not in the saved state, and may be ignored even if the object is
in the saved state.
At and after ZODB 3.6, setting _p_changed to a true value for a ghost
object activates the object; prior to 3.6, setting _p_changed to a
true value on a ghost object was ignored.
Note that an object can transition to the changed state only if
it has a data manager. When such a state change occurs, the
'register' method of the data manager must be called, passing the
...
...
@@ -273,8 +282,8 @@ class IPersistentDataManager(Interface):
obj: a persistent object from this Connection.
tid: id of a transaction that wrote an earlier revision.
Raises KeyError if tid does not exist or if tid deleted a revision of
obj.
Raises KeyError if tid does not exist or if tid deleted a revision of
obj.
"""
def
register
(
object
):
...
...
src/persistent/tests/persistent.txt
View file @
17b317b3
...
...
@@ -87,7 +87,7 @@ Test Persistent with Data Manager
Next try some tests of an object with a data manager. The DM class is
a simple testing stub.
>>> p = P()
>>> dm = DM()
>>> p._p_oid = "00000012"
...
...
@@ -194,20 +194,24 @@ The _p_serial attribute is not affected by calling setstate.
Change Ghost test
-----------------
If an object is a ghost and it's _p_changed is set to True, it should
have no effect.
If an object is a ghost and its _p_changed is set to True (any true value),
it should activate (unghostify) the object. This behavior is new in ZODB
3.6; before then, an attempt to do "ghost._p_changed = True" was ignored.
>>> p = P()
>>> p._p_jar = DM()
>>> p._p_oid = 1
>>> p._p_deactivate()
>>> p._p_changed
>>> p._p_state
>>> p._p_changed
# None
>>> p._p_state
# ghost state
-1
>>> p._p_changed = True
>>> p._p_changed
>>> p._p_state
-1
1
>>> p._p_state # changed state
1
>>> p.x
42
Activate, deactivate, and invalidate
------------------------------------
...
...
@@ -338,7 +342,7 @@ have a custom metaclass.
Basic type structure
--------------------
>>> Persistent.__dictoffset__
>>> Persistent.__dictoffset__
0
>>> Persistent.__weakrefoffset__
0
...
...
@@ -392,7 +396,7 @@ The various _p_ attributes are unaffected by slots.
>>> p._p_state
0
If the most-derived class does not specify
If the most-derived class does not specify
>>> p_shouldHaveDict.__dictoffset__ > 0
True
...
...
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