#14157: Birthday calculation failing silently
---------------------------+------------------------------------------------
Reporter: nil_von_9wo | Owner: nobody
Status: new | Milestone:
Component: Uncategorized | Version: 1.2
Keywords: | Stage: Unreviewed
Has_patch: 0 |
---------------------------+------------------------------------------------
I have a model:
{{{
class Fighter (models.Model):
name = models.CharField(max_length=100)
birth_date = models.DateField(blank=True, null=True)
def age(self):
return calculate_age(self.birth_date)
}}}
calculate_age is as follow:
{{{
def calculate_age(born):
today = datetime.datetime.today()
try: # raised when birth day is February 29 and the current year is
not a leap year
birthday = born.replace(year=today.year)
except ValueError:
birthday = born.replace(year=today.year, day=born.day-1)
import pdb; pdb.set_trace();
if birthday > today:
return today.year - born.year -1
else:
return today.year - born.year
}}}
This function works perfectly from the command line.
However, as it is, from within a running django server, Fighter.age()
returns no results.
By experimenting, I learned Fighter.age() will return a result if I return
something (anything) in calculate_age() ''before'' it hits
{{{if birthday > today:}}}
By returning both values before that point, I verified that neither was
"None", however they may not be the same data type.
I'm going to try casting them to match the type, but I was advised I
should report this incident.
--
Ticket URL: <http://code.djangoproject.com/ticket/14157>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.