m1 actually has more "fields" than meet the eye: besides person and group,
there are also person_id and group_id (and these are the attributes that go
into the database). The *_id attributes are set when the object attributes are
set -- that is, the assignment
m1.person = ringo # implicit in your code, executed by the initializer
causes also
m1.person_id =
ringo.id
In your sample, this was done before ringo and beatles were saved, so the id
value was still None.
A case can be made for updating the ids for FK fields before saving an object,
which will make your problem go away. Off hand, I'm -0 on that -- it reeks of
"action at a distance", on pure instinct I'd say it will probably cause more
problems than it solves.
Shai.