#8892: ForeignKey relation not saved as expected
---------------------------------------+------------------------------------
          Reporter:  julien            |         Owner:  nobody
            Status:  reopened          |     Milestone:        
         Component:  Database wrapper  |       Version:  1.0   
        Resolution:                    |      Keywords:        
             Stage:  Unreviewed        |     Has_patch:  0     
        Needs_docs:  0                 |   Needs_tests:  0     
Needs_better_patch:  0                 |  
---------------------------------------+------------------------------------
Comment (by julien):

 Replying to [comment:1 mrts]:
 > This is quite expected as `a` doesn't have a primary key before saving.
 It '''can''' not have it theoretically. This is documented in
 http://docs.djangoproject.com/en/dev/ref/models/instances/#auto-
 incrementing-primary-keys .

 I already knew that it's only after saving the object once that it gets a
 primary key. But in this case I just assumed that creating the relation
 (`b.a = a`) would not be affected whether it was set before or after the
 related object was saved. I assumed that subsequently saving `a` then `b`
 would also save the relation, no matter the prior sequence of operations.

 I've been using Django for a while now, and I've always been quite careful
 with this logic. But here I admit I was quite surprised by this behaviour
 (in fact, I was equally surprised that I didn't get hit by this before,
 which is why I identified it as a bug in Django).

 Malcolm, you're talking about improving the error message, but the code
 above doesn't actually generate any error. In any case, I'd be happy to
 learn more about how that all works when the docs are updated.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8892#comment:3>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to