﻿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
14157	Birthday calculation failing silently	nil_von_9wo	nobody	"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.


"		closed	Uncategorized	1.2		invalid			Unreviewed	0	0	0	0	0	0
