Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Getters and setters on fields
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeremy Bowers  
View profile  
 More options Dec 15 2006, 11:23 pm
From: Jeremy Bowers <j...@jerf.org>
Date: Fri, 15 Dec 2006 23:23:07 -0500
Local: Fri, Dec 15 2006 11:23 pm
Subject: Re: Getters and setters on fields
Jacob Kaplan-Moss wrote:
> The patch looks pretty good to me; it applies cleanly and all the unit tests
> pass (you get major props for including 'em on the first pass :).

> However, I do have one quibble: the addition of ``self._django_initializing``
> inside ``Model.__init__`` has a pretty nasty "smell" to it. Is that there to
> prevent the setter from being called during initialization? If so, why?

> Also, a few lines of documentation need to be added (to docs/model-api.txt)
> before this can be checked in.

It is there to prevent application of the setters upon initialization,
as you guess.

Running the setters at initialization causes two major problems:

* First, using the code in my unit test, during the initial construction
of the GetSet, "has_both" was set first. This caused the getter to fire
and correctly set updated_length_field to 1. Then, as the Django
initialization proceded, updated_length_field was set to the default of
0 since no value was passed in, and the computed value was blown away.
(Amusingly, the current end result is the same, the updated_length_field
is set to the default of 0. But now it's *documented* that setters
aren't called :) , rather than having setters run in an indeterminate
order on partially-constructed objects.)

* Suppose you have a setter that performs a transform T(x). The first
time you set it, you'll get T(x) in the database. The next time you
retrieve it, the setter applies the transform again, and you end up with
T(T(x)). Or to put it another way, loading an object and immediately
saving it is no longer an effective no-op. That's bad. (Putting it lightly.)

I started down a path to try to "solve" these problems, but everything
was complicated and made me nervous about performance issues.

I agree that adding that flag is sort of bad, but everything else I came
up with was worse. I'm open to suggestions.

A revised patch including documentation has been added; it supercedes
the previous one.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google