#36489: OneToOneField + concurrent get_or_create results in wrong object in
field
cache
-------------------------------------+-------------------------------------
Reporter: Brian Atkinson | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Brian Atkinson):
The part that bit us is that the object left behind from the failed
creation could have different field values from the actual row read from
the database. The example above had much of that stripped, but imagine one
of the fields provided during creation is context sensitive (example: UUID
of the request), then the `parent.child` could have data that differs from
the returned row.
More concretely, consider adding the following to the Child table:
{{{
context_id = models.UUIDField(default=uuid.uuid4)
}}}
I would expect the following to hold:
{{{
assert child.context_id == parent.child.context_id
}}}
From my perspective as a user, I might prefer an additional read to
populate that relation over that inequality not holding. At least I think
that would be my preference. The comments about an "identity map" make me
confident that there are a lot more details around how the APIs should be
behaving that I'm not unaware of. Is there an assumption that the
following should be true?
{{{
assert child is parent.child
}}}
Thanks for taking the time to consider this issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/36489#comment:5>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070197c88782a3-10702324-1c32-4c1a-8278-cac9a56244b4-000000%40eu-central-1.amazonses.com.