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
63afe3a2
Kaydet (Commit)
63afe3a2
authored
Nis 07, 2017
tarafından
Ian Foote
Kaydeden (comit)
Tim Graham
May 01, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28043 -- Prevented AddIndex and RemoveIndex from mutating model state.
üst
4b0211da
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
1 deletion
+34
-1
models.py
django/db/migrations/operations/models.py
+5
-1
state.py
django/db/migrations/state.py
+3
-0
1.11.1.txt
docs/releases/1.11.1.txt
+3
-0
test_operations.py
tests/migrations/test_operations.py
+23
-0
No files found.
django/db/migrations/operations/models.py
Dosyayı görüntüle @
63afe3a2
...
...
@@ -760,7 +760,10 @@ class AddIndex(IndexOperation):
def
state_forwards
(
self
,
app_label
,
state
):
model_state
=
state
.
models
[
app_label
,
self
.
model_name_lower
]
model_state
.
options
[
self
.
option_name
]
.
append
(
self
.
index
)
indexes
=
list
(
model_state
.
options
[
self
.
option_name
])
indexes
.
append
(
self
.
index
.
clone
())
model_state
.
options
[
self
.
option_name
]
=
indexes
state
.
reload_model
(
app_label
,
self
.
model_name_lower
,
delay
=
True
)
def
database_forwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
model
=
to_state
.
apps
.
get_model
(
app_label
,
self
.
model_name
)
...
...
@@ -802,6 +805,7 @@ class RemoveIndex(IndexOperation):
model_state
=
state
.
models
[
app_label
,
self
.
model_name_lower
]
indexes
=
model_state
.
options
[
self
.
option_name
]
model_state
.
options
[
self
.
option_name
]
=
[
idx
for
idx
in
indexes
if
idx
.
name
!=
self
.
name
]
state
.
reload_model
(
app_label
,
self
.
model_name_lower
,
delay
=
True
)
def
database_forwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
model
=
from_state
.
apps
.
get_model
(
app_label
,
self
.
model_name
)
...
...
django/db/migrations/state.py
Dosyayı görüntüle @
63afe3a2
...
...
@@ -546,6 +546,9 @@ class ModelState:
app_label
=
self
.
app_label
,
name
=
self
.
name
,
fields
=
list
(
self
.
fields
),
# Since options are shallow-copied here, operations such as
# AddIndex must replace their option (e.g 'indexes') rather
# than mutating it.
options
=
dict
(
self
.
options
),
bases
=
self
.
bases
,
managers
=
list
(
self
.
managers
),
...
...
docs/releases/1.11.1.txt
Dosyayı görüntüle @
63afe3a2
...
...
@@ -69,3 +69,6 @@ Bugfixes
* Fixed crash in ``BaseGeometryWidget.get_context()`` when overriding existing
``attrs`` (:ticket:`28105`).
* Prevented ``AddIndex`` and ``RemoveIndex`` from mutating model state
(:ticket:`28043`).
tests/migrations/test_operations.py
Dosyayı görüntüle @
63afe3a2
...
...
@@ -1489,6 +1489,29 @@ class OperationTests(OperationTestBase):
self
.
unapply_operations
(
"test_rmin"
,
project_state
,
operations
=
operations
)
self
.
assertIndexExists
(
"test_rmin_pony"
,
[
"pink"
,
"weight"
])
def
test_add_index_state_forwards
(
self
):
project_state
=
self
.
set_up_test_model
(
'test_adinsf'
)
index
=
models
.
Index
(
fields
=
[
'pink'
],
name
=
'test_adinsf_pony_pink_idx'
)
old_model
=
project_state
.
apps
.
get_model
(
'test_adinsf'
,
'Pony'
)
new_state
=
project_state
.
clone
()
operation
=
migrations
.
AddIndex
(
'Pony'
,
index
)
operation
.
state_forwards
(
'test_adinsf'
,
new_state
)
new_model
=
new_state
.
apps
.
get_model
(
'test_adinsf'
,
'Pony'
)
self
.
assertIsNot
(
old_model
,
new_model
)
def
test_remove_index_state_forwards
(
self
):
project_state
=
self
.
set_up_test_model
(
'test_rminsf'
)
index
=
models
.
Index
(
fields
=
[
'pink'
],
name
=
'test_rminsf_pony_pink_idx'
)
migrations
.
AddIndex
(
'Pony'
,
index
)
.
state_forwards
(
'test_rminsf'
,
project_state
)
old_model
=
project_state
.
apps
.
get_model
(
'test_rminsf'
,
'Pony'
)
new_state
=
project_state
.
clone
()
operation
=
migrations
.
RemoveIndex
(
'Pony'
,
'test_rminsf_pony_pink_idx'
)
operation
.
state_forwards
(
'test_rminsf'
,
new_state
)
new_model
=
new_state
.
apps
.
get_model
(
'test_rminsf'
,
'Pony'
)
self
.
assertIsNot
(
old_model
,
new_model
)
def
test_alter_field_with_index
(
self
):
"""
Test AlterField operation with an index to ensure indexes created via
...
...
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