[Django] #18638: Reverse OneToOne relationship does not save properly.

12 views
Skip to first unread message

Django

unread,
Jul 16, 2012, 3:54:16 PM7/16/12
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
----------------------------------------------+--------------------
Reporter: dhatch | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
When the reverse side of a one-to-one relationship is assigned to and the
model is saved, the association is not properly written to the database.

Example:

Models:
{{{
class Tag(models.Model):
data = models.OneToOneField("Data")

class Data(models.Model):
pass
}}}

Run:
{{{
data = Data()
t = Tag.objects.create()
data.tag = t
data.save()
# refresh from db
data = Data.objects.get(pk=data.pk)
data.tag # raises DoesNotExist
}}}

Attached is a patch including a test case which illustrates this issue.
To run the test case cd to the tests directory then...

{{{export PYTHONPATH=`pwd`:`pwd`/..; ./runtests.py --settings=test_sqlite
one_to_one_regress}}}

'''test_reverse_one_to_one_save''' should fail.

--
Ticket URL: <https://code.djangoproject.com/ticket/18638>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 16, 2012, 4:03:13 PM7/16/12
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
-------------------------------------+-------------------------------------
Reporter: dhatch | Owner: dhatch
Type: Bug | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dhatch):

* owner: nobody => dhatch


--
Ticket URL: <https://code.djangoproject.com/ticket/18638#comment:2>

Django

unread,
Jul 16, 2012, 3:59:07 PM7/16/12
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
-------------------------------------+-------------------------------------
Reporter: dhatch | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anonymous):

* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/18638#comment:1>

Django

unread,
Jul 16, 2012, 4:03:20 PM7/16/12
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
-------------------------------------+-------------------------------------
Reporter: dhatch | Owner: dhatch
Type: Bug | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dhatch):

* cc: dhatch (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/18638#comment:3>

Django

unread,
Jul 16, 2012, 4:03:44 PM7/16/12
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
-------------------------------------+-------------------------------------
Reporter: dhatch | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dhatch):

* owner: dhatch => nobody


--
Ticket URL: <https://code.djangoproject.com/ticket/18638#comment:4>

Django

unread,
Jul 16, 2012, 4:37:58 PM7/16/12
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
-------------------------------------+-------------------------------------
Reporter: dhatch | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 1
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* status: new => closed
* resolution: => worksforme


Comment:

You're seeing the expected behavior. You'd need to call `tag.save()`.

The API for 1-to-1 relationships isn't totally symmetrical -- after all it
isn't at the SQL level.

--
Ticket URL: <https://code.djangoproject.com/ticket/18638#comment:5>

Django

unread,
Sep 29, 2020, 9:48:22 AM9/29/20
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
-------------------------------------+-------------------------------------
Reporter: David Hatch | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: 1.4
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* resolution: worksforme => wontfix
* type: Bug => New feature


Comment:

#32056 was closed as a duplicate, we can treat this as a request for a new
feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/18638#comment:6>

Django

unread,
Mar 24, 2023, 1:31:49 AM3/24/23
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
-------------------------------------+-------------------------------------
Reporter: David Hatch | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 1.4
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

#34433 was closed as a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/18638#comment:7>

Django

unread,
Apr 27, 2023, 8:24:37 AM4/27/23
to django-...@googlegroups.com
#18638: Reverse OneToOne relationship does not save properly.
-------------------------------------+-------------------------------------
Reporter: David Hatch | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 1.4
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by NKSM):

Replying to [comment:5 Aymeric Augustin]:


> You're seeing the expected behavior. You'd need to call `tag.save()`.
>
> The API for 1-to-1 relationships isn't totally symmetrical -- after all
it isn't at the SQL level.

This should be documented here:
https://docs.djangoproject.com/en/dev/topics/db/examples/one_to_one/.

The way it is now described is confusing.

--
Ticket URL: <https://code.djangoproject.com/ticket/18638#comment:8>

Reply all
Reply to author
Forward
0 new messages