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
4f7467b6
Unverified
Kaydet (Commit)
4f7467b6
authored
Nis 03, 2018
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Nis 03, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #28577 -- Added check for HStoreField to prevent mutable default.
üst
167d9852
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
4 deletions
+35
-4
hstore.py
django/contrib/postgres/fields/hstore.py
+4
-1
test_hstore.py
tests/postgres_tests/test_hstore.py
+31
-3
No files found.
django/contrib/postgres/fields/hstore.py
Dosyayı görüntüle @
4f7467b6
...
@@ -6,15 +6,18 @@ from django.core import exceptions
...
@@ -6,15 +6,18 @@ from django.core import exceptions
from
django.db.models
import
Field
,
TextField
,
Transform
from
django.db.models
import
Field
,
TextField
,
Transform
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
gettext_lazy
as
_
from
.mixins
import
CheckFieldDefaultMixin
__all__
=
[
'HStoreField'
]
__all__
=
[
'HStoreField'
]
class
HStoreField
(
Field
):
class
HStoreField
(
CheckFieldDefaultMixin
,
Field
):
empty_strings_allowed
=
False
empty_strings_allowed
=
False
description
=
_
(
'Map of strings to strings/nulls'
)
description
=
_
(
'Map of strings to strings/nulls'
)
default_error_messages
=
{
default_error_messages
=
{
'not_a_string'
:
_
(
'The value of "
%(key)
s" is not a string or null.'
),
'not_a_string'
:
_
(
'The value of "
%(key)
s" is not a string or null.'
),
}
}
_default_hint
=
(
'dict'
,
'{}'
)
def
db_type
(
self
,
connection
):
def
db_type
(
self
,
connection
):
return
'hstore'
return
'hstore'
...
...
tests/postgres_tests/test_hstore.py
Dosyayı görüntüle @
4f7467b6
import
json
import
json
from
django.core
import
exceptions
,
serializers
from
django.core
import
checks
,
exceptions
,
serializers
from
django.forms
import
Form
from
django.forms
import
Form
from
django.test.utils
import
modify_settings
from
django.test.utils
import
isolate_apps
,
modify_settings
from
.
import
PostgreSQLTestCase
from
.
import
PostgreSQLTestCase
from
.models
import
HStoreModel
from
.models
import
HStoreModel
,
PostgreSQLModel
try
:
try
:
from
django.contrib.postgres
import
forms
from
django.contrib.postgres
import
forms
...
@@ -190,6 +190,34 @@ class TestQuerying(HStoreTestCase):
...
@@ -190,6 +190,34 @@ class TestQuerying(HStoreTestCase):
)
)
@isolate_apps
(
'postgres_tests'
)
class
TestChecks
(
PostgreSQLTestCase
):
def
test_invalid_default
(
self
):
class
MyModel
(
PostgreSQLModel
):
field
=
HStoreField
(
default
=
{})
model
=
MyModel
()
self
.
assertEqual
(
model
.
check
(),
[
checks
.
Warning
(
msg
=
(
"HStoreField default should be a callable instead of an "
"instance so that it's not shared between all field "
"instances."
),
hint
=
'Use a callable instead, e.g., use `dict` instead of `{}`.'
,
obj
=
MyModel
.
_meta
.
get_field
(
'field'
),
id
=
'postgres.E003'
,
)
])
def
test_valid_default
(
self
):
class
MyModel
(
PostgreSQLModel
):
field
=
HStoreField
(
default
=
dict
)
self
.
assertEqual
(
MyModel
()
.
check
(),
[])
class
TestSerialization
(
HStoreTestCase
):
class
TestSerialization
(
HStoreTestCase
):
test_data
=
json
.
dumps
([{
test_data
=
json
.
dumps
([{
'model'
:
'postgres_tests.hstoremodel'
,
'model'
:
'postgres_tests.hstoremodel'
,
...
...
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