Ticket #13357: django-pypy.2.diff

File django-pypy.2.diff, 8.1 KB (added by Alex Gaynor, 14 years ago)

This patch does all of the above, and fixes the cache tests (caused by files not being written because they aren't flushed because they aren't closed)

  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 2c2bcd5..1d3a150 100644
    a b class BaseModelAdmin(object):  
    7373    readonly_fields = ()
    7474
    7575    def __init__(self):
    76         self.formfield_overrides = dict(FORMFIELD_FOR_DBFIELD_DEFAULTS, **self.formfield_overrides)
     76        overrides = FORMFIELD_FOR_DBFIELD_DEFAULTS.copy()
     77        overrides.update(self.formfield_overrides)
     78        self.formfield_overrides = overrides
    7779
    7880    def formfield_for_dbfield(self, db_field, **kwargs):
    7981        """
  • django/core/cache/backends/filebased.py

    diff --git a/django/core/cache/backends/filebased.py b/django/core/cache/backends/filebased.py
    index 91f0b78..4433367 100644
    a b class CacheClass(BaseCache):  
    4242        fname = self._key_to_file(key)
    4343        try:
    4444            f = open(fname, 'rb')
    45             exp = pickle.load(f)
    46             now = time.time()
    47             if exp < now:
     45            try:
     46                exp = pickle.load(f)
     47                now = time.time()
     48                if exp < now:
     49                    f.close()
     50                    self._delete(fname)
     51                else:
     52                    return pickle.load(f)
     53            finally:
    4854                f.close()
    49                 self._delete(fname)
    50             else:
    51                 return pickle.load(f)
    5255        except (IOError, OSError, EOFError, pickle.PickleError):
    5356            pass
    5457        return default
    class CacheClass(BaseCache):  
    6770                os.makedirs(dirname)
    6871
    6972            f = open(fname, 'wb')
    70             now = time.time()
    71             pickle.dump(now + timeout, f, pickle.HIGHEST_PROTOCOL)
    72             pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
     73            try:
     74                now = time.time()
     75                pickle.dump(now + timeout, f, pickle.HIGHEST_PROTOCOL)
     76                pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
     77            finally:
     78                f.close()
    7379        except (IOError, OSError):
    7480            pass
    7581
    class CacheClass(BaseCache):  
    9399        fname = self._key_to_file(key)
    94100        try:
    95101            f = open(fname, 'rb')
    96             exp = pickle.load(f)
    97             now = time.time()
    98             if exp < now:
     102            try:
     103                exp = pickle.load(f)
     104                now = time.time()
     105                if exp < now:
     106                    self._delete(fname)
     107                    return False
     108                else:
     109                    return True
     110            finally:
    99111                f.close()
    100                 self._delete(fname)
    101                 return False
    102             else:
    103                 return True
    104112        except (IOError, OSError, EOFError, pickle.PickleError):
    105113            return False
    106114
  • tests/modeltests/aggregation/models.py

    diff --git a/tests/modeltests/aggregation/models.py b/tests/modeltests/aggregation/models.py
    index e5f0f5d..74e43b8 100644
    a b u'The Definitive Guide to Django: Web Development Done Right'  
    191191
    192192# Calling values on a queryset that has annotations returns the output
    193193# as a dictionary
    194 >>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values()
    195 [{'rating': 4.5, 'isbn': u'159059725', 'name': u'The Definitive Guide to Django: Web Development Done Right', 'pubdate': datetime.date(2007, 12, 6), 'price': Decimal("30..."), 'contact_id': 1, 'id': 1, 'publisher_id': 1, 'pages': 447, 'mean_age': 34.5}]
     194>>> [sorted(o.iteritems()) for o in Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values()]
     195[[('contact_id', 1), ('id', 1), ('isbn', u'159059725'), ('mean_age', 34.5), ('name', u'The Definitive Guide to Django: Web Development Done Right'), ('pages', 447), ('price', Decimal("30...")), ('pubdate', datetime.date(2007, 12, 6)), ('publisher_id', 1), ('rating', 4.5)]]
    196196
    197197>>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values('pk', 'isbn', 'mean_age')
    198198[{'pk': 1, 'isbn': u'159059725', 'mean_age': 34.5}]
    u'The Definitive Guide to Django: Web Development Done Right'  
    203203
    204204# An empty values() call before annotating has the same effect as an
    205205# empty values() call after annotating
    206 >>> Book.objects.filter(pk=1).values().annotate(mean_age=Avg('authors__age'))
    207 [{'rating': 4.5, 'isbn': u'159059725', 'name': u'The Definitive Guide to Django: Web Development Done Right', 'pubdate': datetime.date(2007, 12, 6), 'price': Decimal("30..."), 'contact_id': 1, 'id': 1, 'publisher_id': 1, 'pages': 447, 'mean_age': 34.5}]
     206>>> [sorted(o.iteritems()) for o in Book.objects.filter(pk=1).values().annotate(mean_age=Avg('authors__age'))]
     207[[('contact_id', 1), ('id', 1), ('isbn', u'159059725'), ('mean_age', 34.5), ('name', u'The Definitive Guide to Django: Web Development Done Right'), ('pages', 447), ('price', Decimal("30...")), ('pubdate', datetime.date(2007, 12, 6)), ('publisher_id', 1), ('rating', 4.5)]]
    208208
    209209# Calling annotate() on a ValuesQuerySet annotates over the groups of
    210210# fields to be selected by the ValuesQuerySet.
  • tests/modeltests/expressions/models.py

    diff --git a/tests/modeltests/expressions/models.py b/tests/modeltests/expressions/models.py
    index 76006e1..f6292f5 100644
    a b FieldError: Joined field references are not permitted in this query  
    127127>>> acme.save()
    128128Traceback (most recent call last):
    129129...
    130 TypeError: int() argument must be a string or a number...
     130TypeError: ...
    131131
    132132"""}
  • tests/regressiontests/aggregation_regress/models.py

    diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py
    index 7c51cd1..66a5ff7 100644
    a b FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta  
    174174{'number': 1132, 'select': 1132}
    175175
    176176# Regression for #10064: select_related() plays nice with aggregates
    177 >>> Book.objects.select_related('publisher').annotate(num_authors=Count('authors')).values()[0]
    178 {'rating': 4.0, 'isbn': u'013790395', 'name': u'Artificial Intelligence: A Modern Approach', 'pubdate': datetime.date(1995, 1, 15), 'price': Decimal("82.8..."), 'contact_id': 8, 'id': 5, 'num_authors': 2, 'publisher_id': 3, 'pages': 1132}
     177>>> sorted(Book.objects.select_related('publisher').annotate(num_authors=Count('authors')).values()[0].iteritems())
     178[('contact_id', 8), ('id', 5), ('isbn', u'013790395'), ('name', u'Artificial Intelligence: A Modern Approach'), ('num_authors', 2), ('pages', 1132), ('price', Decimal("82.8...")), ('pubdate', datetime.date(1995, 1, 15)), ('publisher_id', 3), ('rating', 4.0)]
    179179
    180180# Regression for #10010: exclude on an aggregate field is correctly negated
    181181>>> len(Book.objects.annotate(num_authors=Count('authors')))
    FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta  
    219219>>> Book.objects.filter(id__in=[]).aggregate(num_authors=Count('authors'), avg_authors=Avg('authors'), max_authors=Max('authors'), max_price=Max('price'), max_rating=Max('rating'))
    220220{'max_authors': None, 'max_rating': None, 'num_authors': 0, 'avg_authors': None, 'max_price': None}
    221221
    222 >>> Publisher.objects.filter(pk=5).annotate(num_authors=Count('book__authors'), avg_authors=Avg('book__authors'), max_authors=Max('book__authors'), max_price=Max('book__price'), max_rating=Max('book__rating')).values()
    223 [{'max_authors': None, 'name': u"Jonno's House of Books", 'num_awards': 0, 'max_price': None, 'num_authors': 0, 'max_rating': None, 'id': 5, 'avg_authors': None}]
     222>>> list(Publisher.objects.filter(pk=5).annotate(num_authors=Count('book__authors'), avg_authors=Avg('book__authors'), max_authors=Max('book__authors'), max_price=Max('book__price'), max_rating=Max('book__rating')).values()) == [{'max_authors': None, 'name': u"Jonno's House of Books", 'num_awards': 0, 'max_price': None, 'num_authors': 0, 'max_rating': None, 'id': 5, 'avg_authors': None}]
     223True
    224224
    225225# Regression for #10113 - Fields mentioned in order_by() must be included in the GROUP BY.
    226226# This only becomes a problem when the order_by introduces a new join.
Back to Top