Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodbtools
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
Jérome Perrin
zodbtools
Commits
31e7acde
Commit
31e7acde
authored
Apr 30, 2023
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repro
parent
ed268117
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
138 additions
and
1 deletion
+138
-1
iterator_undo/repro_create_storage.py
iterator_undo/repro_create_storage.py
+138
-1
No files found.
iterator_undo/repro_create_storage.py
View file @
31e7acde
import
ZODB
from
contextlib
import
closing
from
ZODB.FileStorage
import
FileStorage
from
ZODB
import
DB
,
TimeStamp
import
persistent
import
time
import
transaction
from
ZODB.utils
import
readable_tid_repr
import
logging
logging
.
basicConfig
(
level
=
logging
.
INFO
)
class
P
(
persistent
.
Persistent
):
def
__init__
(
self
,
value
):
self
.
value
=
value
def
faketime
():
# fake time to have a reproductible database
_xtime0
=
time
.
mktime
(
time
.
strptime
(
"04 Jan 1979"
,
"%d %b %Y"
))
def
xtime_reset
():
global
_xtime
_xtime
=
_xtime0
xtime_reset
()
def
xtime
():
global
_xtime
_xtime
+=
1.1
return
_xtime
time
.
time
=
xtime
def
change_object
(
value
):
with
closing
(
FileStorage
(
filename
))
as
stor
,
closing
(
DB
(
stor
))
as
db
,
closing
(
db
.
open
()
)
as
conn
:
transaction
.
get
().
note
(
value
)
obj
=
conn
.
root
()[
"obj"
]
obj
.
value
=
value
transaction
.
commit
()
filename
=
"repro_initial.fs"
filename_copy
=
"repro_copy.fs"
with
closing
(
FileStorage
(
filename
,
create
=
True
))
as
stor
,
closing
(
DB
(
stor
)
)
as
db
,
closing
(
db
.
open
())
as
conn
:
root
=
conn
.
root
()
obj
=
P
(
"__version_0__"
)
root
[
"obj"
]
=
obj
transaction
.
get
().
note
(
"version 0"
)
transaction
.
commit
()
# make a first version of object
with
closing
(
FileStorage
(
filename
))
as
stor
,
closing
(
DB
(
stor
))
as
db
,
closing
(
db
.
open
()
)
as
conn
:
transaction
.
get
().
note
(
"version 1"
)
obj
=
conn
.
root
()[
"obj"
]
obj
.
value
=
"__version_1__"
transaction
.
commit
()
# make a second version of object
with
closing
(
FileStorage
(
filename
))
as
stor
,
closing
(
DB
(
stor
))
as
db
,
closing
(
db
.
open
()
)
as
conn
:
transaction
.
get
().
note
(
"version 2"
)
obj
=
conn
.
root
()[
"obj"
]
obj
.
value
=
"__version_2__"
transaction
.
commit
()
# undo these two changes ( go back to __version_0__)
with
closing
(
FileStorage
(
filename
))
as
stor
,
closing
(
DB
(
stor
))
as
db
,
closing
(
db
.
open
()
)
as
conn
:
undo_log
=
db
.
undoInfo
(
0
,
2
)
assert
[
u
[
"description"
]
for
u
in
undo_log
]
==
[
"version 2"
,
"version 1"
]
transaction
.
get
().
note
(
"undo 2 and 1 (back to 0)"
)
db
.
undoMultiple
([
u
[
"id"
]
for
u
in
undo_log
])
transaction
.
commit
()
# make a third version of object
with
closing
(
FileStorage
(
filename
))
as
stor
,
closing
(
DB
(
stor
))
as
db
,
closing
(
db
.
open
()
)
as
conn
:
transaction
.
get
().
note
(
"version 3"
)
obj
=
conn
.
root
()[
"obj"
]
assert
obj
.
value
==
"__version_0__"
,
obj
.
value
# check undo was effective
obj
.
value
=
"__version_3__"
transaction
.
commit
()
# undo version 3 ( go back to __version_0__)
with
closing
(
FileStorage
(
filename
))
as
stor
,
closing
(
DB
(
stor
))
as
db
,
closing
(
db
.
open
()
)
as
conn
:
undo_log
=
db
.
undoInfo
(
0
,
1
)
assert
[
u
[
"description"
]
for
u
in
undo_log
]
==
[
"version 3"
,
]
transaction
.
get
().
note
(
"undo 2 and 1 (back to 0)"
)
db
.
undoMultiple
([
u
[
"id"
]
for
u
in
undo_log
])
transaction
.
commit
()
# check the state is OK
with
closing
(
FileStorage
(
filename
))
as
stor
,
closing
(
DB
(
stor
))
as
db
,
closing
(
db
.
open
()
)
as
conn
:
obj
=
conn
.
root
()[
"obj"
]
assert
obj
.
value
==
"__version_0__"
,
obj
.
value
# copy this to a new storage
with
closing
(
FileStorage
(
filename
))
as
stor
,
closing
(
FileStorage
(
filename_copy
,
create
=
True
)
)
as
stor_copy
:
stor_copy
.
copyTransactionsFrom
(
stor
)
with
closing
(
FileStorage
(
filename_copy
))
as
stor
,
closing
(
DB
(
stor
))
as
db
,
closing
(
db
.
open
()
)
as
conn
:
obj
=
conn
.
root
()[
"obj"
]
# AssertionError: __version_1__
assert
obj
.
value
==
"__version_0__"
,
obj
.
value
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