﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
499	[patch] method_save() empty value fix	alberto@…	Adrian Holovaty	"Hi,

I've found a bug in django.core.meta in function method_save which would create SQL statementes with an empty value such as name='' when updating. Those queries would fail (postgresql and mysql). Here is a patch. It fixed my problem but I haven't tested it very thoroughly so typical discalimers apply :). Probably can be done better so feel free to improve.

Great software, I'm so happy to have an excuse to improve my Python skills....



{{{
*** django/core/meta/__init__.py.orig   2005-09-13 17:34:54.591722120 +0200
--- django/core/meta/__init__.py        2005-09-13 17:31:55.037018584 +0200
***************
*** 782,787 ****
--- 782,793 ----
          # If it does already exist, do an UPDATE.
          if cursor.fetchone():
              db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column), False)) for f in non_pks]
+             while 1:
+                 try: 
+                     idx = db_values.index('')
+                     non_pks[idx:idx+1] = []
+                     db_values[idx:idx+1] = []
+                 except: break
              cursor.execute(""UPDATE %s SET %s WHERE %s=%%s"" % (opts.db_table,
                  ','.join(['%s=%%s' % f.column for f in non_pks]), opts.pk.column), db_values + [pk_val])
          else:
}}}




"		closed	Template system	new-admin	major	fixed			Unreviewed	1	0	0	0	0	0
