Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
139
Merge Requests
139
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
6ee95ea3
Commit
6ee95ea3
authored
Dec 27, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XMLExportImport.OrderedPickle: prevent TypeError on dicts with non orderable keys
parent
f80db865
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testXMLPickle.py
...TemplateItem/portal_components/test.erp5.testXMLPickle.py
+23
-1
product/ERP5Type/XMLExportImport/__init__.py
product/ERP5Type/XMLExportImport/__init__.py
+4
-3
No files found.
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testXMLPickle.py
View file @
6ee95ea3
...
...
@@ -33,7 +33,7 @@ import zodbpickle.fastpickle as pickle
import
re
from
io
import
BytesIO
from
six
import
StringIO
from
Products.ERP5Type.XMLExportImport
import
importXML
,
ppml
from
Products.ERP5Type.XMLExportImport
import
importXML
,
OrderedPickler
,
ppml
import
six
import
lxml.etree
...
...
@@ -194,6 +194,7 @@ class TestXMLPickle(XMLPickleTestCase):
self
.
check_and_load
({
'a'
:
1
,
'b'
:
2
})
self
.
check_and_load
({
'hé'
:
'ho'
})
self
.
check_and_load
(
dict
.
fromkeys
(
range
(
3000
)))
self
.
check_and_load
({
1
:
'one'
,
'two'
:
2
})
def
test_tuple
(
self
):
self
.
check_and_load
((
1
,
))
...
...
@@ -346,3 +347,24 @@ class TestXMLPickleStringHeuristics(XMLPickleTestCase):
self
.
assertEqual
(
persistent_ids
,
[
b'
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x01
'
])
class
TestOrderedPickler
(
unittest
.
TestCase
):
def
test_ordered_pickler
(
self
):
def
check
(
obj
,
check_items_order
=
True
):
f
=
BytesIO
()
pickler
=
OrderedPickler
(
f
)
pickler
.
dump
(
obj
)
f
.
seek
(
0
)
reconstructed
=
pickle
.
load
(
f
)
self
.
assertEqual
(
reconstructed
,
obj
)
self
.
assertIs
(
type
(
reconstructed
),
type
(
obj
))
if
check_items_order
:
self
.
assertEqual
(
list
(
reconstructed
.
items
()),
list
(
obj
.
items
()))
check
({
"one"
:
1
,
"two"
:
2
})
check
({
1
:
"one"
,
"two"
:
2
})
check
({
b"one"
:
1
,
b"two"
:
2
})
check
({})
check
(
1
,
check_items_order
=
False
)
check
(
"one"
,
check_items_order
=
False
)
product/ERP5Type/XMLExportImport/__init__.py
View file @
6ee95ea3
...
...
@@ -74,9 +74,10 @@ class OrderedPickler(Pickler):
dispatch
=
Pickler
.
dispatch
.
copy
()
def
save_dict
(
self
,
obj
):
return
Pickler
.
save_dict
(
self
,
OrderedDict
(
sorted
(
obj
.
items
())))
items
=
sorted
(
obj
.
items
(),
key
=
lambda
item
:
str
(
item
[
0
]))
return
Pickler
.
save_dict
(
self
,
OrderedDict
(
items
))
dispatch
[
dict
]
=
save_dict
...
...
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