Ticket #6901: extra-orderby-2.diff

File extra-orderby-2.diff, 1.3 KB (added by Brodie Rao, 17 years ago)

db.models.base with updated extra/order_by usage (uses .values() as before)

  • django/db/models/base.py

     
    304304        manager = cls._default_manager
    305305        if pk_set:
    306306            # Determine whether a record with the primary key already exists.
    307             if manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by():
     307            if manager.filter(pk=pk_val).extra(select={'a': 1}, order_by=('a',)).values('a'):
    308308                # It does already exist, so do an UPDATE.
    309309                if non_pks:
    310310                    values = [(f.name, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
     
    427427                (qn('_order'), op, qn('_order'),
    428428                qn(self._meta.db_table), qn(self._meta.pk.column))]
    429429            params = [self.pk]
    430             obj = self._default_manager.filter(**{order_field.name: getattr(self, order_field.attname)}).extra(where=where, params=params).order_by(order)[:1].get()
     430            obj = self._default_manager.filter(**{order_field.name: getattr(self, order_field.attname)}).extra(where=where, params=params, order_by=(order,))[:1].get()
    431431            setattr(self, cachename, obj)
    432432        return getattr(self, cachename)
    433433
Back to Top