Ticket #862: 862.diff

File 862.diff, 1.6 KB (added by garthk, 19 years ago)

Fix

  • django/core/meta/__init__.py

     
    938938    if not pk_set or not record_exists:
    939939        field_names = [db.db.quote_name(f.column) for f in opts.fields if not isinstance(f, AutoField)]
    940940        placeholders = ['%s'] * len(field_names)
    941         db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.attname), True)) for f in opts.fields if not isinstance(f, AutoField)]
     941        db_values = []
     942        # Pre-save all values. We could do this as a one-liner, but then
     943        # it'd be near-impossible to figure out which field was causing
     944        # the problem.
     945        for f in opts.fields:
     946            if not isinstance(f, AutoField):
     947                try:
     948                    val = getattr(self, f.attname)
     949                    f_presave = f.pre_save(val, True)
     950                    db_presave = f.get_db_prep_save(f_presave)
     951                    db_values.append(db_presave)
     952                except Exception, ex:
     953                    # Append a message to the exception's arguments,
     954                    # and then re-raise it. Yes, Veronica, this works.
     955                    msg = "save() can't handle field %s" % f.attname
     956                    ex.args = tuple(list(ex.args)+[msg])
     957                    raise
    942958        if opts.order_with_respect_to:
    943959            field_names.append(db.db.quote_name('_order'))
    944960            # TODO: This assumes the database supports subqueries.
Back to Top