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
2f9861d8
Kaydet (Commit)
2f9861d8
authored
Eki 31, 2016
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Eki 31, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27148 -- Fixed ModelMultipleChoiceField crash with invalid UUID.
üst
de91c172
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
10 deletions
+13
-10
__init__.py
django/db/models/fields/__init__.py
+3
-6
test_uuid.py
tests/model_fields/test_uuid.py
+4
-4
test_uuid.py
tests/model_forms/test_uuid.py
+6
-0
No files found.
django/db/models/fields/__init__.py
Dosyayı görüntüle @
2f9861d8
...
...
@@ -2371,20 +2371,17 @@ class UUIDField(Field):
if
value
is
None
:
return
None
if
not
isinstance
(
value
,
uuid
.
UUID
):
try
:
value
=
uuid
.
UUID
(
value
)
except
AttributeError
:
raise
TypeError
(
self
.
error_messages
[
'invalid'
]
%
{
'value'
:
value
})
value
=
self
.
to_python
(
value
)
if
connection
.
features
.
has_native_uuid_field
:
return
value
return
value
.
hex
def
to_python
(
self
,
value
):
if
value
and
not
isinstance
(
value
,
uuid
.
UUID
):
if
not
isinstance
(
value
,
uuid
.
UUID
):
try
:
return
uuid
.
UUID
(
value
)
except
ValueError
:
except
(
AttributeError
,
ValueError
)
:
raise
exceptions
.
ValidationError
(
self
.
error_messages
[
'invalid'
],
code
=
'invalid'
,
...
...
tests/model_fields/test_uuid.py
Dosyayı görüntüle @
2f9861d8
...
...
@@ -40,17 +40,17 @@ class TestSaveLoad(TestCase):
self
.
assertIsNone
(
loaded
.
field
)
def
test_pk_validated
(
self
):
with
self
.
assertRaisesMessage
(
Type
Error
,
'is not a valid UUID'
):
with
self
.
assertRaisesMessage
(
exceptions
.
Validation
Error
,
'is not a valid UUID'
):
PrimaryKeyUUIDModel
.
objects
.
get
(
pk
=
{})
with
self
.
assertRaisesMessage
(
Type
Error
,
'is not a valid UUID'
):
with
self
.
assertRaisesMessage
(
exceptions
.
Validation
Error
,
'is not a valid UUID'
):
PrimaryKeyUUIDModel
.
objects
.
get
(
pk
=
[])
def
test_wrong_value
(
self
):
with
self
.
assertRaisesMessage
(
ValueError
,
'badly formed hexadecimal UUID string
'
):
with
self
.
assertRaisesMessage
(
exceptions
.
ValidationError
,
'is not a valid UUID
'
):
UUIDModel
.
objects
.
get
(
field
=
'not-a-uuid'
)
with
self
.
assertRaisesMessage
(
ValueError
,
'badly formed hexadecimal UUID string
'
):
with
self
.
assertRaisesMessage
(
exceptions
.
ValidationError
,
'is not a valid UUID
'
):
UUIDModel
.
objects
.
create
(
field
=
'not-a-uuid'
)
...
...
tests/model_forms/test_uuid.py
Dosyayı görüntüle @
2f9861d8
from
__future__
import
unicode_literals
from
django
import
forms
from
django.core.exceptions
import
ValidationError
from
django.test
import
TestCase
from
.models
import
UUIDPK
...
...
@@ -27,3 +28,8 @@ class ModelFormBaseTest(TestCase):
msg
=
"The UUIDPK could not be changed because the data didn't validate."
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
form
.
save
()
def
test_model_multiple_choice_field_uuid_pk
(
self
):
f
=
forms
.
ModelMultipleChoiceField
(
UUIDPK
.
objects
.
all
())
with
self
.
assertRaisesMessage
(
ValidationError
,
"'invalid_uuid' is not a valid UUID."
):
f
.
clean
([
'invalid_uuid'
])
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