On 12 May 2013, at 00:55, Russell Keith-Magee <[email protected]> wrote:
> I'm sure I understand this argument. Python objects are passed around by 
> reference, not by value, so if you've passed in a Django object deep into 
> another library, that library will be pointing at the same instance. If the 
> instance is changed, everywhere holding a handle to that reference will be 
> updated.
> 
> To that end - I want to make sure that we're clear about what we're talking 
> about here. 
> 
> What is on the table is essentially adding a refresh() call on an object 
> instance that is an API analog of ".get(id=self.id)" (although the 
> implementation will need to do a bit more than that).
> 
> We are *not* talking about ticket #17, object instance caching. Calling 
> refresh() *will not* update *every* instance of a given object. The following 
> would be the effective API:
> 
> >>> a = MyObj.objects.get(id=42)
> >>> a.message = 'hello'
> >>> a.save()
> >>> b = MyObj.objects.get(id=42)
> >>> c = MyObj.objects.get(id=42)
> 
> >>> a.message = 'goodbye'
> >>> a.save()
> >>> print b.message
> 'hello'
> >>> b.refresh()
> >>> print b.message
> 'goodbye'
> >>> print c.message
> 'hello'

I was under the impression that the suggested use case was more like this:

>>> a = MyObj.objects.get(id=42)
>>> a.message = 'hello'
>>> b = {'obj': a}
>>> print b['obj'].message
'hello'
>>> c = MyObj.objects.get(id=42)
>>> c.message = 'goodbye'
>>> c.save()
>>> a = MyObj.objects.get(id=42)  # existing 'workaround', gives us a new 
>>> instance
>>> print a.message
'goodbye'
>>> print b['obj'].message  # b['obj'] still points to the original instance `a`
'hello'

If a reload() method existed, `a` could have been reloaded with `a.reload()`, 
and then `b['obj']` would have been up-to-date as well. As it stands, every 
reference to `a` has to be explicitly re-fetched from the database.

Am I missing something obvious?


- Andy

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to