Opened 10 years ago

Closed 8 years ago

#24028 closed Bug (wontfix)

Related instance caching causes abstraction leaks from Field.get_db_prep_save

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

Description

This is a regression from the introduction of 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.)

Change History (4)

comment:1 by Tim Graham, 10 years ago

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.

comment:2 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

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.

comment:3 by Tim Graham, 8 years ago

#27825 was a duplicate.

comment:4 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

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

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