#927 closed defect (fixed)
non-integer primary keys are broken since new-admin merge
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Metasystem | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
From "svn annotate django/core/meta/fields.py", line 721 onwards:
1434 adrian def get_db_prep_save(self,value): 1434 adrian if value == '' or value == None: 1434 adrian return None 1434 adrian else: 1434 adrian return int(value)
That "return int(value)" obviously is not compatible with non-integer primary keys. The problem occurs outside of the admin - i.e. when creating objects and setting foreign keys manually in my migration script.
Change History (8)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
comment:5 by , 19 years ago
As per rjwittams suggestion, I have changed my local copy to:
def get_db_prep_save(self,value):
return self.rel.get_related_field().get_db_prep_save(value)
And of course it does work, now. About the issue with fields being null, wouldn't the delegated method for the model field
check that automatically? Pardon my ignorance, as I am just begining to dig into the internals.
comment:6 by , 19 years ago
Hey anonymous,
The point is that a ForeignKey field could be null, so that needs to be an accepted value. Any primary key cannot be null, so would always complain.
So
def get_db_prep_save(self,value): if value == '' or value == None: return None else: return self.rel.get_related_field().get_db_prep_save(value)
is probably the right thing for now.
comment:8 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
So the right fix here needs to take the rel.get_related_field() into account, as it will have the same type of value as that. Maybe delegate to the db_prep_save of that field. But it also needs to take related fields being null when the field it is related to cannot be.