﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19170	Add a way to control related fields reverse cache	dirleyrls	nobody	"I have a very specific use-case where we use a database view to represent some data. I've mapeed it using a unmanaged model like this:

{{{#!python
# concrete table
class Something(models.Model):
  # ...


class SomethingHelperView(models.Model):
  something = models.OneToOneField(Something, related_name='helper')
  counter = models.PositiveIntegerField()
  
  class Meta:
    managed = False
    db_table = 'something_helper_view'
}}}


When I do:

{{{#!python
>>> something = Something.objects.get(pk=1)
>>> something.helper.counter
10
>>> # some operation that will update the counter
>>> # ...
>>> something.helper.counter
10
}}}

This was not the behavior I wanted to have. Since I'm using a database view, I expect it to always be ""fresh"". I want that, every time I access my helper, it hits the database, bringing me a fresh value. That's the point of this view.

Poking around through Django's code, I realized that related fields have their back references cached. It's ok, I understand the purpose of that cache. But I got frustrated when I discovered I can't just turn it off. It would be good to be able to turn it off.

And for the record, currently I'm working around this issue doing like this:

{{{#!python
Something.fresh_helper = property(lambda self: SomethingHelperView.get(something=self))
}}}"	New feature	closed	Database layer (models, ORM)	1.4	Normal	wontfix	orm realted cache		Unreviewed	0	0	0	0	0	0
