[Django] #24028: Related instance caching causes abstraction leaks from Field.get_db_prep_save

10 views
Skip to first unread message

Django

unread,
Dec 19, 2014, 9:46:57 PM12/19/14
to django-...@googlegroups.com
#24028: Related instance caching causes abstraction leaks from
Field.get_db_prep_save
-------------------------------------+-------------------------------------
Reporter: jdunck | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 1.5
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
This is a regression from the introduction of
[[https://docs.djangoproject.com/en/dev/releases/1.5/#caching-of-related-
model-instances|related instance caching]] in 1.5.

{{{
class Foo(models.Model):
pass

class Bar(models.Model):
foo = models.OneToOneField(Foo)
value = models.DecimalField()

>>> foo = Foo.objects.create()
>>> bar = Bar.objects.create(foo=foo, value='1.0')
>>> foo.bar.value == Decimal('1.0')
}}}

The last line passes under 1.4, fails under 1.5+.

I think it would be reasonable to have a flag to Model.save which updates
field attributes to the result of Field.to_python(value), which would plug
this leak.

(I found this issue in production code under test, while upgrading from
1.4 to 1.5 on the way to 1.7.)

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

Django

unread,
Dec 22, 2014, 1:57:39 PM12/22/14
to django-...@googlegroups.com
#24028: Related instance caching causes abstraction leaks from
Field.get_db_prep_save
-------------------------------------+-------------------------------------
Reporter: jdunck | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.5
(models, ORM) |
Severity: Normal | Resolution:
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 timgraham):

IMO, it makes more sense to always have the proposed behavior or never to
have it. A flag seems like unnecessary complexity, but I'll be interested
to see how others feel about this. Maybe it would be good to raise the
issue on django-developers.

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

Django

unread,
Dec 25, 2014, 7:12:10 AM12/25/14
to django-...@googlegroups.com
#24028: Related instance caching causes abstraction leaks from
Field.get_db_prep_save
-------------------------------------+-------------------------------------
Reporter: jdunck | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.5
(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
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

Marking as accepted as depending on the results of the discussion we could
at least document this behavior as it comes up in support channels once in
a while.

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

Django

unread,
Feb 9, 2017, 11:58:16 AM2/9/17
to django-...@googlegroups.com
#24028: Related instance caching causes abstraction leaks from
Field.get_db_prep_save
-------------------------------------+-------------------------------------
Reporter: Jeremy Dunck | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.5
(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 Tim Graham):

#27825 was a duplicate.

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

Django

unread,
Feb 16, 2017, 11:22:13 AM2/16/17
to django-...@googlegroups.com
#24028: Related instance caching causes abstraction leaks from
Field.get_db_prep_save
-------------------------------------+-------------------------------------
Reporter: Jeremy Dunck | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.5
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

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


Comment:

Closing as wontfix per the discussion on #27825. The consensus is to
document this limitation.

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

Reply all
Reply to author
Forward
0 new messages