Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
a8f4553a
Kaydet (Commit)
a8f4553a
authored
Ara 04, 2013
tarafından
Loic Bistuer
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21555 -- Made ValidationError pickable.
Thanks trac username zanuxzan for the report and original patch.
üst
41ebc483
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletion
+50
-1
exceptions.py
django/core/exceptions.py
+9
-1
test_picklable.py
tests/validation/test_picklable.py
+41
-0
No files found.
django/core/exceptions.py
Dosyayı görüntüle @
a8f4553a
...
@@ -4,6 +4,7 @@ Global Django exception and warning classes.
...
@@ -4,6 +4,7 @@ Global Django exception and warning classes.
from
functools
import
reduce
from
functools
import
reduce
import
operator
import
operator
from
django.utils
import
six
from
django.utils.encoding
import
force_text
from
django.utils.encoding
import
force_text
...
@@ -84,10 +85,17 @@ class ValidationError(Exception):
...
@@ -84,10 +85,17 @@ class ValidationError(Exception):
list or dictionary can be an actual `list` or `dict` or an instance
list or dictionary can be an actual `list` or `dict` or an instance
of ValidationError with its `error_list` or `error_dict` attribute set.
of ValidationError with its `error_list` or `error_dict` attribute set.
"""
"""
# PY2 can't pickle naive exception: http://bugs.python.org/issue1692335.
super
(
ValidationError
,
self
)
.
__init__
(
message
,
code
,
params
)
if
isinstance
(
message
,
ValidationError
):
if
isinstance
(
message
,
ValidationError
):
if
hasattr
(
message
,
'error_dict'
):
if
hasattr
(
message
,
'error_dict'
):
message
=
message
.
error_dict
message
=
message
.
error_dict
elif
not
hasattr
(
message
,
'message'
):
# PY2 has a `message` property which is always there so we can't
# duck-type on it. It was introduced in Python 2.5 and already
# deprecated in Python 2.6.
elif
not
hasattr
(
message
,
'message'
if
six
.
PY3
else
'code'
):
message
=
message
.
error_list
message
=
message
.
error_list
else
:
else
:
message
,
code
,
params
=
message
.
message
,
message
.
code
,
message
.
params
message
,
code
,
params
=
message
.
message
,
message
.
code
,
message
.
params
...
...
tests/validation/test_picklable.py
0 → 100644
Dosyayı görüntüle @
a8f4553a
import
pickle
from
unittest
import
TestCase
from
django.core.exceptions
import
ValidationError
class
PickableValidationErrorTestCase
(
TestCase
):
def
test_validationerror_is_picklable
(
self
):
original
=
ValidationError
(
'a'
,
code
=
'something'
)
unpickled
=
pickle
.
loads
(
pickle
.
dumps
(
original
))
self
.
assertIs
(
unpickled
,
unpickled
.
error_list
[
0
])
self
.
assertEqual
(
original
.
message
,
unpickled
.
message
)
self
.
assertEqual
(
original
.
code
,
unpickled
.
code
)
original
=
ValidationError
(
'a'
,
code
=
'something'
)
unpickled
=
pickle
.
loads
(
pickle
.
dumps
(
ValidationError
(
original
)))
self
.
assertIs
(
unpickled
,
unpickled
.
error_list
[
0
])
self
.
assertEqual
(
original
.
message
,
unpickled
.
message
)
self
.
assertEqual
(
original
.
code
,
unpickled
.
code
)
original
=
ValidationError
([
'a'
,
'b'
])
unpickled
=
pickle
.
loads
(
pickle
.
dumps
(
original
))
self
.
assertEqual
(
original
.
error_list
[
0
]
.
message
,
unpickled
.
error_list
[
0
]
.
message
)
self
.
assertEqual
(
original
.
error_list
[
1
]
.
message
,
unpickled
.
error_list
[
1
]
.
message
)
original
=
ValidationError
([
'a'
,
'b'
])
unpickled
=
pickle
.
loads
(
pickle
.
dumps
(
ValidationError
(
original
)))
self
.
assertEqual
(
original
.
error_list
[
0
]
.
message
,
unpickled
.
error_list
[
0
]
.
message
)
self
.
assertEqual
(
original
.
error_list
[
1
]
.
message
,
unpickled
.
error_list
[
1
]
.
message
)
original
=
ValidationError
([
ValidationError
(
'a'
),
ValidationError
(
'b'
)])
unpickled
=
pickle
.
loads
(
pickle
.
dumps
(
original
))
self
.
assertIs
(
unpickled
.
args
[
0
][
0
],
unpickled
.
error_list
[
0
])
self
.
assertEqual
(
original
.
error_list
[
0
]
.
message
,
unpickled
.
error_list
[
0
]
.
message
)
self
.
assertEqual
(
original
.
error_list
[
1
]
.
message
,
unpickled
.
error_list
[
1
]
.
message
)
message_dict
=
{
'field1'
:
[
'a'
,
'b'
],
'field2'
:
[
'c'
,
'd'
]}
original
=
ValidationError
(
message_dict
)
unpickled
=
pickle
.
loads
(
pickle
.
dumps
(
original
))
self
.
assertEqual
(
unpickled
.
message_dict
,
message_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