Commit 07f2d192 authored by Joseph Kocherhans's avatar Joseph Kocherhans
Browse files

[1.1.X] Fixed #12546. Objects with a __len__ that returns 0 can now be...

[1.1.X] Fixed #12546. Objects with a __len__ that returns 0 can now be serialized. Thanks, casobn for the report and Alex Gaynor for the patch and tests. Backport of r12576 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12577 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 692d122c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -277,7 +277,7 @@ class Field(object):
        return first_choice + list(self.flatchoices)

    def _get_val_from_obj(self, obj):
        if obj:
        if obj is not None:
            return getattr(obj, self.attname)
        else:
            return self.get_default()
+6 −1
Original line number Diff line number Diff line
@@ -253,3 +253,8 @@ class ExplicitInheritBaseModel(BaseModel):
    parent = models.OneToOneField(BaseModel)
    child_data = models.IntegerField()

class LengthModel(models.Model):
    data = models.IntegerField()

    def __len__(self):
        return self.data
+4 −1
Original line number Diff line number Diff line
@@ -8,7 +8,8 @@ forward, backwards and self references.
"""


import unittest, datetime
import datetime
import unittest
from cStringIO import StringIO

from django.utils.functional import curry
@@ -321,6 +322,8 @@ The end."""),
    (inherited_obj, 900, InheritAbstractModel, {'child_data':37,'parent_data':42}),
    (inherited_obj, 910, ExplicitInheritBaseModel, {'child_data':37,'parent_data':42}),
    (inherited_obj, 920, InheritBaseModel, {'child_data':37,'parent_data':42}),
    (data_obj, 1004, LengthModel, 0),
    (data_obj, 1005, LengthModel, 1),
]

# Because Oracle treats the empty string as NULL, Oracle is expected to fail