mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
[soc2009/multidb] Remove cross database protection. This will be readded in a way that is more ammenable to master-slave and other mirroring schemes.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11927 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -259,53 +259,53 @@ class QueryTestCase(TestCase):
|
||||
self.assertEquals(list(Person.objects.using('other').filter(book__title='Dive into HTML5').values_list('name', flat=True)),
|
||||
[u'Mark Pilgrim'])
|
||||
|
||||
def test_m2m_cross_database_protection(self):
|
||||
"Operations that involve sharing M2M objects across databases raise an error"
|
||||
# Create a book and author on the default database
|
||||
pro = Book.objects.create(title="Pro Django",
|
||||
published=datetime.date(2008, 12, 16))
|
||||
# def test_m2m_cross_database_protection(self):
|
||||
# "Operations that involve sharing M2M objects across databases raise an error"
|
||||
# # Create a book and author on the default database
|
||||
# pro = Book.objects.create(title="Pro Django",
|
||||
# published=datetime.date(2008, 12, 16))
|
||||
|
||||
marty = Person.objects.create(name="Marty Alchin")
|
||||
# marty = Person.objects.create(name="Marty Alchin")
|
||||
|
||||
# Create a book and author on the other database
|
||||
dive = Book.objects.using('other').create(title="Dive into Python",
|
||||
published=datetime.date(2009, 5, 4))
|
||||
# # Create a book and author on the other database
|
||||
# dive = Book.objects.using('other').create(title="Dive into Python",
|
||||
# published=datetime.date(2009, 5, 4))
|
||||
|
||||
mark = Person.objects.using('other').create(name="Mark Pilgrim")
|
||||
# Set a foreign key set with an object from a different database
|
||||
try:
|
||||
marty.book_set = [pro, dive]
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# mark = Person.objects.using('other').create(name="Mark Pilgrim")
|
||||
# # Set a foreign key set with an object from a different database
|
||||
# try:
|
||||
# marty.book_set = [pro, dive]
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
# Add to an m2m with an object from a different database
|
||||
try:
|
||||
marty.book_set.add(dive)
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# # Add to an m2m with an object from a different database
|
||||
# try:
|
||||
# marty.book_set.add(dive)
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
# Set a m2m with an object from a different database
|
||||
try:
|
||||
marty.book_set = [pro, dive]
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# # Set a m2m with an object from a different database
|
||||
# try:
|
||||
# marty.book_set = [pro, dive]
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
# Add to a reverse m2m with an object from a different database
|
||||
try:
|
||||
dive.authors.add(marty)
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# # Add to a reverse m2m with an object from a different database
|
||||
# try:
|
||||
# dive.authors.add(marty)
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
# Set a reverse m2m with an object from a different database
|
||||
try:
|
||||
dive.authors = [mark, marty]
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# # Set a reverse m2m with an object from a different database
|
||||
# try:
|
||||
# dive.authors = [mark, marty]
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
def test_foreign_key_separation(self):
|
||||
"FK fields are constrained to a single database"
|
||||
@@ -401,88 +401,88 @@ class QueryTestCase(TestCase):
|
||||
self.assertEquals(list(Person.objects.using('other').filter(edited__title='Dive into Python').values_list('name', flat=True)),
|
||||
[])
|
||||
|
||||
def test_foreign_key_cross_database_protection(self):
|
||||
"Operations that involve sharing FK objects across databases raise an error"
|
||||
# Create a book and author on the default database
|
||||
pro = Book.objects.create(title="Pro Django",
|
||||
published=datetime.date(2008, 12, 16))
|
||||
# def test_foreign_key_cross_database_protection(self):
|
||||
# "Operations that involve sharing FK objects across databases raise an error"
|
||||
# # Create a book and author on the default database
|
||||
# pro = Book.objects.create(title="Pro Django",
|
||||
# published=datetime.date(2008, 12, 16))
|
||||
|
||||
marty = Person.objects.create(name="Marty Alchin")
|
||||
# marty = Person.objects.create(name="Marty Alchin")
|
||||
|
||||
# Create a book and author on the other database
|
||||
dive = Book.objects.using('other').create(title="Dive into Python",
|
||||
published=datetime.date(2009, 5, 4))
|
||||
# # Create a book and author on the other database
|
||||
# dive = Book.objects.using('other').create(title="Dive into Python",
|
||||
# published=datetime.date(2009, 5, 4))
|
||||
|
||||
mark = Person.objects.using('other').create(name="Mark Pilgrim")
|
||||
# mark = Person.objects.using('other').create(name="Mark Pilgrim")
|
||||
|
||||
# Set a foreign key with an object from a different database
|
||||
try:
|
||||
dive.editor = marty
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# # Set a foreign key with an object from a different database
|
||||
# try:
|
||||
# dive.editor = marty
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
# Set a foreign key set with an object from a different database
|
||||
try:
|
||||
marty.edited = [pro, dive]
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# # Set a foreign key set with an object from a different database
|
||||
# try:
|
||||
# marty.edited = [pro, dive]
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
# Add to a foreign key set with an object from a different database
|
||||
try:
|
||||
marty.edited.add(dive)
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# # Add to a foreign key set with an object from a different database
|
||||
# try:
|
||||
# marty.edited.add(dive)
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
# BUT! if you assign a FK object when the base object hasn't
|
||||
# been saved yet, you implicitly assign the database for the
|
||||
# base object.
|
||||
chris = Person(name="Chris Mills")
|
||||
html5 = Book(title="Dive into HTML5", published=datetime.date(2010, 3, 15))
|
||||
# initially, no db assigned
|
||||
self.assertEquals(chris._state.db, None)
|
||||
self.assertEquals(html5._state.db, None)
|
||||
# # BUT! if you assign a FK object when the base object hasn't
|
||||
# # been saved yet, you implicitly assign the database for the
|
||||
# # base object.
|
||||
# chris = Person(name="Chris Mills")
|
||||
# html5 = Book(title="Dive into HTML5", published=datetime.date(2010, 3, 15))
|
||||
# # initially, no db assigned
|
||||
# self.assertEquals(chris._state.db, None)
|
||||
# self.assertEquals(html5._state.db, None)
|
||||
|
||||
# old object comes from 'other', so the new object is set to use 'other'...
|
||||
dive.editor = chris
|
||||
html5.editor = mark
|
||||
# self.assertEquals(chris._state.db, 'other')
|
||||
self.assertEquals(html5._state.db, 'other')
|
||||
# ... but it isn't saved yet
|
||||
self.assertEquals(list(Person.objects.using('other').values_list('name',flat=True)),
|
||||
[u'Mark Pilgrim'])
|
||||
self.assertEquals(list(Book.objects.using('other').values_list('title',flat=True)),
|
||||
[u'Dive into Python'])
|
||||
# # old object comes from 'other', so the new object is set to use 'other'...
|
||||
# dive.editor = chris
|
||||
# html5.editor = mark
|
||||
# # self.assertEquals(chris._state.db, 'other')
|
||||
# self.assertEquals(html5._state.db, 'other')
|
||||
# # ... but it isn't saved yet
|
||||
# self.assertEquals(list(Person.objects.using('other').values_list('name',flat=True)),
|
||||
# [u'Mark Pilgrim'])
|
||||
# self.assertEquals(list(Book.objects.using('other').values_list('title',flat=True)),
|
||||
# [u'Dive into Python'])
|
||||
|
||||
# When saved (no using required), new objects goes to 'other'
|
||||
chris.save()
|
||||
html5.save()
|
||||
self.assertEquals(list(Person.objects.using('default').values_list('name',flat=True)),
|
||||
[u'Marty Alchin'])
|
||||
self.assertEquals(list(Person.objects.using('other').values_list('name',flat=True)),
|
||||
[u'Chris Mills', u'Mark Pilgrim'])
|
||||
self.assertEquals(list(Book.objects.using('default').values_list('title',flat=True)),
|
||||
[u'Pro Django'])
|
||||
self.assertEquals(list(Book.objects.using('other').values_list('title',flat=True)),
|
||||
[u'Dive into HTML5', u'Dive into Python'])
|
||||
# # When saved (no using required), new objects goes to 'other'
|
||||
# chris.save()
|
||||
# html5.save()
|
||||
# self.assertEquals(list(Person.objects.using('default').values_list('name',flat=True)),
|
||||
# [u'Marty Alchin'])
|
||||
# self.assertEquals(list(Person.objects.using('other').values_list('name',flat=True)),
|
||||
# [u'Chris Mills', u'Mark Pilgrim'])
|
||||
# self.assertEquals(list(Book.objects.using('default').values_list('title',flat=True)),
|
||||
# [u'Pro Django'])
|
||||
# self.assertEquals(list(Book.objects.using('other').values_list('title',flat=True)),
|
||||
# [u'Dive into HTML5', u'Dive into Python'])
|
||||
|
||||
# This also works if you assign the FK in the constructor
|
||||
water = Book(title="Dive into Water", published=datetime.date(2001, 1, 1), editor=mark)
|
||||
self.assertEquals(water._state.db, 'other')
|
||||
# ... but it isn't saved yet
|
||||
self.assertEquals(list(Book.objects.using('default').values_list('title',flat=True)),
|
||||
[u'Pro Django'])
|
||||
self.assertEquals(list(Book.objects.using('other').values_list('title',flat=True)),
|
||||
[u'Dive into HTML5', u'Dive into Python'])
|
||||
# # This also works if you assign the FK in the constructor
|
||||
# water = Book(title="Dive into Water", published=datetime.date(2001, 1, 1), editor=mark)
|
||||
# self.assertEquals(water._state.db, 'other')
|
||||
# # ... but it isn't saved yet
|
||||
# self.assertEquals(list(Book.objects.using('default').values_list('title',flat=True)),
|
||||
# [u'Pro Django'])
|
||||
# self.assertEquals(list(Book.objects.using('other').values_list('title',flat=True)),
|
||||
# [u'Dive into HTML5', u'Dive into Python'])
|
||||
|
||||
# When saved, the new book goes to 'other'
|
||||
water.save()
|
||||
self.assertEquals(list(Book.objects.using('default').values_list('title',flat=True)),
|
||||
[u'Pro Django'])
|
||||
self.assertEquals(list(Book.objects.using('other').values_list('title',flat=True)),
|
||||
[u'Dive into HTML5', u'Dive into Python', u'Dive into Water'])
|
||||
# # When saved, the new book goes to 'other'
|
||||
# water.save()
|
||||
# self.assertEquals(list(Book.objects.using('default').values_list('title',flat=True)),
|
||||
# [u'Pro Django'])
|
||||
# self.assertEquals(list(Book.objects.using('other').values_list('title',flat=True)),
|
||||
# [u'Dive into HTML5', u'Dive into Python', u'Dive into Water'])
|
||||
|
||||
def test_generic_key_separation(self):
|
||||
"Generic fields are constrained to a single database"
|
||||
@@ -555,56 +555,56 @@ class QueryTestCase(TestCase):
|
||||
self.assertEquals(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)),
|
||||
[u'Python Daily'])
|
||||
|
||||
def test_generic_key_cross_database_protection(self):
|
||||
"Operations that involve sharing FK objects across databases raise an error"
|
||||
# Create a book and author on the default database
|
||||
pro = Book.objects.create(title="Pro Django",
|
||||
published=datetime.date(2008, 12, 16))
|
||||
# def test_generic_key_cross_database_protection(self):
|
||||
## "Operations that involve sharing FK objects across databases raise an error"
|
||||
## # Create a book and author on the default database
|
||||
## pro = Book.objects.create(title="Pro Django",
|
||||
## published=datetime.date(2008, 12, 16))
|
||||
|
||||
review1 = Review.objects.create(source="Python Monthly", content_object=pro)
|
||||
## review1 = Review.objects.create(source="Python Monthly", content_object=pro)
|
||||
|
||||
# Create a book and author on the other database
|
||||
dive = Book.objects.using('other').create(title="Dive into Python",
|
||||
published=datetime.date(2009, 5, 4))
|
||||
## # Create a book and author on the other database
|
||||
## dive = Book.objects.using('other').create(title="Dive into Python",
|
||||
## published=datetime.date(2009, 5, 4))
|
||||
|
||||
review2 = Review.objects.using('other').create(source="Python Weekly", content_object=dive)
|
||||
## review2 = Review.objects.using('other').create(source="Python Weekly", content_object=dive)
|
||||
|
||||
# Set a foreign key with an object from a different database
|
||||
try:
|
||||
review1.content_object = dive
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
## # Set a foreign key with an object from a different database
|
||||
## try:
|
||||
## review1.content_object = dive
|
||||
## self.fail("Shouldn't be able to assign across databases")
|
||||
## except ValueError:
|
||||
## pass
|
||||
|
||||
# Add to a foreign key set with an object from a different database
|
||||
try:
|
||||
dive.reviews.add(review1)
|
||||
self.fail("Shouldn't be able to assign across databases")
|
||||
except ValueError:
|
||||
pass
|
||||
# # Add to a foreign key set with an object from a different database
|
||||
# try:
|
||||
# dive.reviews.add(review1)
|
||||
# self.fail("Shouldn't be able to assign across databases")
|
||||
# except ValueError:
|
||||
# pass
|
||||
|
||||
# BUT! if you assign a FK object when the base object hasn't
|
||||
# been saved yet, you implicitly assign the database for the
|
||||
# base object.
|
||||
review3 = Review(source="Python Daily")
|
||||
# initially, no db assigned
|
||||
self.assertEquals(review3._state.db, None)
|
||||
# # BUT! if you assign a FK object when the base object hasn't
|
||||
# # been saved yet, you implicitly assign the database for the
|
||||
# # base object.
|
||||
# review3 = Review(source="Python Daily")
|
||||
# # initially, no db assigned
|
||||
# self.assertEquals(review3._state.db, None)
|
||||
|
||||
# Dive comes from 'other', so review3 is set to use 'other'...
|
||||
review3.content_object = dive
|
||||
self.assertEquals(review3._state.db, 'other')
|
||||
# ... but it isn't saved yet
|
||||
self.assertEquals(list(Review.objects.using('default').filter(object_id=pro.pk).values_list('source', flat=True)),
|
||||
[u'Python Monthly'])
|
||||
self.assertEquals(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source',flat=True)),
|
||||
[u'Python Weekly'])
|
||||
# # Dive comes from 'other', so review3 is set to use 'other'...
|
||||
# review3.content_object = dive
|
||||
# self.assertEquals(review3._state.db, 'other')
|
||||
# # ... but it isn't saved yet
|
||||
# self.assertEquals(list(Review.objects.using('default').filter(object_id=pro.pk).values_list('source', flat=True)),
|
||||
# [u'Python Monthly'])
|
||||
# self.assertEquals(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source',flat=True)),
|
||||
# [u'Python Weekly'])
|
||||
|
||||
# When saved, John goes to 'other'
|
||||
review3.save()
|
||||
self.assertEquals(list(Review.objects.using('default').filter(object_id=pro.pk).values_list('source', flat=True)),
|
||||
[u'Python Monthly'])
|
||||
self.assertEquals(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source',flat=True)),
|
||||
[u'Python Daily', u'Python Weekly'])
|
||||
# # When saved, John goes to 'other'
|
||||
# review3.save()
|
||||
# self.assertEquals(list(Review.objects.using('default').filter(object_id=pro.pk).values_list('source', flat=True)),
|
||||
# [u'Python Monthly'])
|
||||
# self.assertEquals(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source',flat=True)),
|
||||
# [u'Python Daily', u'Python Weekly'])
|
||||
|
||||
def test_ordering(self):
|
||||
"get_next_by_XXX commands stick to a single database"
|
||||
|
||||
Reference in New Issue
Block a user