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
e917ea6b
Kaydet (Commit)
e917ea6b
authored
Şub 14, 2018
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29126 -- Doc'd the behavior of QuerySet.update_or_create() with manually specified pks.
üst
7ec0fdf6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
querysets.txt
docs/ref/models/querysets.txt
+4
-0
tests.py
tests/get_or_create/tests.py
+13
-0
No files found.
docs/ref/models/querysets.txt
Dosyayı görüntüle @
e917ea6b
...
...
@@ -1988,6 +1988,10 @@ As described above in :meth:`get_or_create`, this method is prone to a
race-condition which can result in multiple rows being inserted simultaneously
if uniqueness is not enforced at the database level.
Like :meth:`get_or_create` and :meth:`create`, if you're using manually
specified primary keys and an object needs to be created but the key already
exists in the database, an :exc:`~django.db.IntegrityError` is raised.
``bulk_create()``
~~~~~~~~~~~~~~~~~
...
...
tests/get_or_create/tests.py
Dosyayı görüntüle @
e917ea6b
...
...
@@ -444,6 +444,19 @@ class UpdateOrCreateTests(TestCase):
self
.
assertEqual
(
obj
.
last_name
,
'NotHarrison'
)
class
UpdateOrCreateTestsWithManualPKs
(
TestCase
):
def
test_create_with_duplicate_primary_key
(
self
):
"""
If an existing primary key is specified with different values for other
fields, then IntegrityError is raised and data isn't updated.
"""
ManualPrimaryKeyTest
.
objects
.
create
(
id
=
1
,
data
=
'Original'
)
with
self
.
assertRaises
(
IntegrityError
):
ManualPrimaryKeyTest
.
objects
.
update_or_create
(
id
=
1
,
data
=
'Different'
)
self
.
assertEqual
(
ManualPrimaryKeyTest
.
objects
.
get
(
id
=
1
)
.
data
,
'Original'
)
class
UpdateOrCreateTransactionTests
(
TransactionTestCase
):
available_apps
=
[
'get_or_create'
]
...
...
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