﻿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
13122	ForeignKey class calls own get_db_prep_save tests prior to the related field get_db_prep_save	SeniorHuevo	nobody	"This is a problem when you have created a custom field to use a complex python type and you wish to use that custom field as a primary key.

On line 811 of django/db/models/fields/related.py

{{{
    def get_db_prep_save(self, value, connection):
        if value == '' or value == None:
            return None
        else:
            return self.rel.get_related_field().get_db_prep_save(value,
                connection=connection)
}}}

This may result in an AttributeError being rased if the python type only compares to the exact same python type.

it's better to let the custom class handle it

{{{
    def get_db_prep_save(self, value, connection):
        try:
            if value == '' or value == None:
                return None
        except AttributeError:
            pass

        return self.rel.get_related_field().get_db_prep_save(value,
            connection=connection)
}}}
"		closed	Database layer (models, ORM)	1.1		invalid			Unreviewed	1	0	0	0	0	0
