Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#25550 closed Cleanup/optimization (fixed)

Deprecate direct assignment to the reverse side of a related set

Reported by: Tim Graham Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As proposed by Ansii on django-developers:

>>> obj.reverse_fk_set = RelatedObj.objects.all()

What happens is that the RelatedObj.objects.all() queryset is
iterated and each object of the queryset is saved with the fk changed
to point to the obj. An implicit save.

Now, I don't like the implicit saves at all. A variable assignment
should not cause a database save. So, I would like to deprecate the
current behavior. Assignment to reverse_fk_set (and I guess this goes
for m2m, too) is no longer allowed. Instead you will need to
explicitly do:

 >>> obj.reverse_fk_set.set(RelatedObj.objects.all())

Now you are calling a method, and saving in this situation is OK and
analogous to other related manager methods.

Lets raise a deprecation warning on direct assignment to the
reverse_fk_set and remove it. The message would be
something like "Direct assignment to the reverse side of a related set
is deprecated. Use .set() instead."

Change History (9)

comment:1 by Tim Graham, 9 years ago

Has patch: set

comment:2 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 9c5e2728:

Fixed #25550 -- Deprecated direct assignment to the reverse side of a related set.

comment:4 by Tim Graham <timograham@…>, 9 years ago

In c7b8d5d:

Refs #25550 -- Removed reverse related set assignment in selenium tests.

comment:5 by GitHub <noreply@…>, 8 years ago

In 5fa43705:

Refs #25550 -- Corrected deprecation message for assigning M2M relations.

comment:6 by Tim Graham <timograham@…>, 8 years ago

In 83b950e9:

[1.10.x] Refs #25550 -- Corrected deprecation message for assigning M2M relations.

Backport of 5fa4370543658aedd79dc554d8c52684d6c7cbca from master

comment:7 by Tim Graham <timograham@…>, 8 years ago

In 8dac9890:

Refs #25550 -- Removed a deprecated reverse assignment example in docs.

comment:8 by Tim Graham <timograham@…>, 8 years ago

In e1f93e2b:

[1.10.x] Refs #25550 -- Removed a deprecated reverse assignment example in docs.

Backport of 8dac9890a5941e7b59ea0ebebed400965941fe09 from master

comment:9 by Tim Graham <timograham@…>, 8 years ago

In ed251246:

Refs #25550 -- Removed support for direct assignment to the reverse side of a related set.

Note: See TracTickets for help on using tickets.
Back to Top