On Tue, May 14, 2013 at 12:09 AM, Russell Keith-Magee <
[email protected]> wrote:
> As far as I can make out, that's exactly the same use case -- you're just
> making the example a little bit more explicit regarding the fact that 'a'
> is an object referred to by reference, so if 'a' is updated, b['a'] will
> also be updated.
>
> The point I was trying to make is that we're *not* talking about every
> instance of "object with PK 42" being transparently updated. It's an
> explicit API call on a specific object instance.
>
I think what he is saying is that this is not just shorthand for some other
way of achieving the same behavior. It's a totally new behavior that has
plenty of corner cases such as foreign keys, and especially OneToOneFields.
This is the shortest workaround I can come up with for the .refresh()
method: "a.__dict__ = dict(a.__dict__).update(type(a).objects.get(**{a._
meta.pk.name: a.pk}).__dict__)". Unfortunately, that clobbers any non-field
attributes you've changed since you created the instance (though it
preserves new ones). Alternatively, you could iterate over Meta.fields
calling "setattr(old_a, field_name, getattr(new_a, field_name))" for each
one, but that has the problem that field setters may expect to do some
massaging of the data on the way in which can cause data corruption.
Basically this is a Hard Problem(tm) with no obvious workaround.
Best,
Alex Ogier
--
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.