On 3/6/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > 2) If a related attribute currently has a value of None, should the > > __get__ method return None, or raise a DoesNotExist if accessed? Does > > this behaviour change if the attribute is set null=True? > > I don't understand this, because null = False and blank = True seems > like it should be impossible.
A freshly constructed object doesn't require you to assign all values; so a1 = Article(headline='xyz') print a1.reporter throws DoesNotExist, rather than returning None. There is an analogous situation using __set__: a1.reporter = None print a1.reporter At the moment the broken cache means this returns None, but with a fixed cache, the assignment is fine, but the accessor raises an exception. This is currently in keeping with the 'no validation until save()' approach. The question is whether the exception is more helpful that None in these cases. > > a) make add()/remove()/clear()/__set__ implicit save points. > > This means your object would have to totally valid at the point you > assigned to the first relation field. Not sure this will always be > possible (two non-null foreign keys, for example?). Am I missing > something here? No - you're correct. Revised version: the SQL table update for ForeignKey and OneToOneField is taken out of object.save(), and made part of the descriptor, so a1.reporter = r1 is immediately applied to the database, with regular numeric, text etc fields applied at the save(). This makes ForeignKey and OneToOneField behaviour exactly analogous to ManyToMany fields. Now that I think about it, I'm +1 on this revised option. It solves the save() direction problem, and introduces parity between all related fields. Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---