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
cc6bcc6f
Kaydet (Commit)
cc6bcc6f
authored
Ara 29, 2017
tarafından
shanghui
Kaydeden (comit)
Tim Graham
Ock 03, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28867 -- Added system check for a model property that clashes with a related field accessor.
üst
fbf64728
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
3 deletions
+42
-3
base.py
django/db/models/base.py
+24
-3
checks.txt
docs/ref/checks.txt
+2
-0
test_models.py
tests/invalid_models_tests/test_models.py
+16
-0
No files found.
django/db/models/base.py
Dosyayı görüntüle @
cc6bcc6f
...
@@ -1191,9 +1191,10 @@ class Model(metaclass=ModelBase):
...
@@ -1191,9 +1191,10 @@ class Model(metaclass=ModelBase):
*
cls
.
_check_long_column_names
(),
*
cls
.
_check_long_column_names
(),
]
]
clash_errors
=
(
clash_errors
=
(
cls
.
_check_id_field
()
+
*
cls
.
_check_id_field
(),
cls
.
_check_field_name_clashes
()
+
*
cls
.
_check_field_name_clashes
(),
cls
.
_check_model_name_db_lookup_clashes
()
*
cls
.
_check_model_name_db_lookup_clashes
(),
*
cls
.
_check_property_name_related_field_accessor_clashes
(),
)
)
errors
.
extend
(
clash_errors
)
errors
.
extend
(
clash_errors
)
# If there are field name clashes, hide consequent column name
# If there are field name clashes, hide consequent column name
...
@@ -1421,6 +1422,26 @@ class Model(metaclass=ModelBase):
...
@@ -1421,6 +1422,26 @@ class Model(metaclass=ModelBase):
)
)
return
errors
return
errors
@classmethod
def
_check_property_name_related_field_accessor_clashes
(
cls
):
errors
=
[]
property_names
=
cls
.
_meta
.
_property_names
related_field_accessors
=
(
f
.
get_attname
()
for
f
in
cls
.
_meta
.
_get_fields
(
reverse
=
False
)
if
f
.
is_relation
and
f
.
related_model
is
not
None
)
for
accessor
in
related_field_accessors
:
if
accessor
in
property_names
:
errors
.
append
(
checks
.
Error
(
"The property '
%
s' clashes with a related field "
"accessor."
%
accessor
,
obj
=
cls
,
id
=
'models.E025'
,
)
)
return
errors
@classmethod
@classmethod
def
_check_index_together
(
cls
):
def
_check_index_together
(
cls
):
"""Check the value of "index_together" option."""
"""Check the value of "index_together" option."""
...
...
docs/ref/checks.txt
Dosyayı görüntüle @
cc6bcc6f
...
@@ -292,6 +292,8 @@ Models
...
@@ -292,6 +292,8 @@ Models
underscore as it collides with the query lookup syntax.
underscore as it collides with the query lookup syntax.
* **models.E024**: The model name ``<model>`` cannot contain double underscores
* **models.E024**: The model name ``<model>`` cannot contain double underscores
as it collides with the query lookup syntax.
as it collides with the query lookup syntax.
* **models.E025**: The property ``<property name>`` clashes with a related
field accessor.
Security
Security
--------
--------
...
...
tests/invalid_models_tests/test_models.py
Dosyayı görüntüle @
cc6bcc6f
...
@@ -706,6 +706,22 @@ class OtherModelTests(SimpleTestCase):
...
@@ -706,6 +706,22 @@ class OtherModelTests(SimpleTestCase):
)
)
])
])
def
test_property_and_related_field_accessor_clash
(
self
):
class
Model
(
models
.
Model
):
fk
=
models
.
ForeignKey
(
'self'
,
models
.
CASCADE
)
@property
def
fk_id
(
self
):
pass
self
.
assertEqual
(
Model
.
check
(),
[
Error
(
"The property 'fk_id' clashes with a related field accessor."
,
obj
=
Model
,
id
=
'models.E025'
,
)
])
@override_settings
(
TEST_SWAPPED_MODEL_BAD_VALUE
=
'not-a-model'
)
@override_settings
(
TEST_SWAPPED_MODEL_BAD_VALUE
=
'not-a-model'
)
def
test_swappable_missing_app_name
(
self
):
def
test_swappable_missing_app_name
(
self
):
class
Model
(
models
.
Model
):
class
Model
(
models
.
Model
):
...
...
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