Ticket #8990: reset-extra.diff
File reset-extra.diff, 7.0 KB (added by , 16 years ago) |
---|
-
django/db/models/base.py
diff --git a/django/db/models/base.py b/django/db/models/base.py index f94d25c..2653244 100644
a b class Model(object): 351 351 if pk_set: 352 352 # Determine whether a record with the primary key already exists. 353 353 if (force_update or (not force_insert and 354 manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by())): 354 manager.filter(pk=pk_val).\ 355 extra(select=False, where=False, params=False, tables=False, order_by=False).\ 356 extra(select={'a': 1}).values('a').order_by())): 355 357 # It does already exist, so do an UPDATE. 356 358 if force_update or non_pks: 357 359 values = [(f, None, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks] -
django/db/models/sql/query.py
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index b4525f1..4d32924 100644
a b class Query(object): 1649 1649 select_pairs[name] = (entry, entry_params) 1650 1650 # This is order preserving, since self.extra_select is a SortedDict. 1651 1651 self.extra_select.update(select_pairs) 1652 elif select is not None: 1653 self.extra_select = SortedDict() 1654 1652 1655 if where: 1653 1656 self.extra_where += tuple(where) 1657 elif where is not None: 1658 self.extra_where = () 1659 1654 1660 if params: 1655 1661 self.extra_params += tuple(params) 1662 elif params is not None: 1663 self.extra_where = () 1664 1656 1665 if tables: 1657 1666 self.extra_tables += tuple(tables) 1667 elif tables is not None: 1668 self.extra_tables = () 1669 1658 1670 if order_by: 1659 1671 self.extra_order_by = order_by 1672 elif order_by is not None: 1673 self.extra_order_by = () 1660 1674 1661 1675 def trim_extra_select(self, names): 1662 1676 """ -
new file tests/modeltests/extra_save/models.py
diff --git a/tests/modeltests/extra_save/__init__.py b/tests/modeltests/extra_save/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/modeltests/extra_save/models.py b/tests/modeltests/extra_save/models.py new file mode 100644 index 0000000..cb7ca10
- + 1 """test for bug #8990 2 """ 3 4 from django.db import models 5 6 class Shelf(models.Model): 7 name = models.CharField(max_length=50) 8 9 def __unicode__(self): 10 return u"%s the shelf" % self.name 11 12 13 class BookManager(models.Manager): 14 def get_query_set(self): 15 return super(BookManager, self).get_query_set().\ 16 select_related('shelf').\ 17 extra(select={'shelf_name': 'extra_save_shelf.name'}) 18 19 20 class Book(models.Model): 21 name = models.CharField(max_length=50) 22 shelf = models.ForeignKey(Shelf) 23 24 objects = BookManager() 25 26 def __unicode__(self): 27 return u"%s the book" % self.name 28 29 30 __test__ = {'API_TESTS':""" 31 >>> shelf = Shelf(name="Foo") 32 >>> shelf.save() 33 >>> book = Book(name="bar", shelf=shelf) 34 >>> book.save() # initial save works fine 35 36 >>> Book.objects.get(pk=1) # querying works as well 37 <Book: bar the book> 38 39 # subsequent saves work too... 40 >>> book.save() 41 42 # ...instead of failing with: 43 #Traceback (most recent call last): 44 # ... 45 #OperationalError: no such column: extra_save_shelf.name 46 """ 47 } 48 No newline at end of file