Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #100, allow ``None`` to get sent to the database regardless of …

…whether the

field in question is nullable.  This prevents the None from getting cast
to a value appropriate to the field and will result in IntegrityErrors.
This is *more* desirable than non-null values getting stored
incorrectly.  Especial thanks to @mkosler for being insistent on this.
  • Loading branch information...
commit ce738d6dd89edc7d9850c368a91cd9f063f5a3a5 1 parent 5532bba
Charles Leifer authored
Showing with 4 additions and 4 deletions.
  1. +1 −1  peewee.py
  2. +3 −3 tests.py
2  peewee.py
View
@@ -2241,7 +2241,7 @@ def render_field_template(self, quote_char=''):
return self.field_template % params
def db_value(self, value):
- if (self.null and value is None):
+ if value is None:
return None
return self.column.db_value(value)
6 tests.py
View
@@ -66,7 +66,7 @@ def __unicode__(self):
class Entry(TestModel):
pk = PrimaryKeyField()
title = CharField(max_length=50, verbose_name='Wacky title')
- content = TextField()
+ content = TextField(default='')
pub_date = DateTimeField(null=True)
blog = ForeignKeyField(Blog, cascade=True)
@@ -97,7 +97,7 @@ class EntryTwo(Entry):
class User(TestModel):
username = CharField(max_length=50)
blog = ForeignKeyField(Blog, null=True)
- active = BooleanField(db_index=True)
+ active = BooleanField(db_index=True, default=False)
class Meta:
db_table = 'users'
@@ -2138,7 +2138,7 @@ def test_select_related_multiple(self):
# didn't select title/content/pub_date on entries, so make sure they're none
for r in results:
self.assertEqual(r.entry.title, None)
- self.assertEqual(r.entry.content, None)
+ self.assertEqual(r.entry.content, '') # <-- default value
self.assertEqual(r.entry.pub_date, None)
self.assertFalse(r.entry.pk == None)
Please sign in to comment.
Something went wrong with that request. Please try again.