#18778: ForeignKey to a model with a CharField primary key produces unexpected
results for an empty-string PK value
----------------------------------------------+--------------------
Reporter: Ubercore | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
{{{
class ModelA(models.Model):
code = models.CharField(max_length=50, primary_key=True)
class ModelB(models.Model):
model_a = models.ForeignKey(ModelA, blank=True, null=True,
max_length=50)
}}}
In this case, if there's an instance of {{{ModelA}}} such that
{{{instance_a.code == ''}}}, {{{ModelB}}} will not be able to reference it
properly. Upon save, {{{db.models.fields.related.ForeignKey}}} will change
{{{model_a_id}}} from {{{''}}} to {{{NULL}}}. While this is an odd case,
and I don't particularly like the situation of having an empty string as a
primary key, I think Django should at least be able to handle it. The
offending code is at
[https://github.com/django/django/blob/master/django/db/models/fields/related.py#L987].
--
Ticket URL: <https://code.djangoproject.com/ticket/18778>
Django <https://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 https://groups.google.com/groups/opt_out.