Hi, I'm seeing some really weird behaviour when saving new instances of
certain models. After calling save() the instance's primary key isn't
set, despite the data having been inserted properly, and if I fetch the
newest instance of the model in question I get the expected result, I
get the data I just saved. 

After some digging I discovered that this happens due to the call to
manager._insert() in save_base() in the Model class (either on line 553
or line 556 in django/db/models/base.py ) returning None, while it
should have returned the primary key of the newly inserted row.

So, anyone have any ideas about why this could be happening?


This for instance happens with the following model, but I've seen it happen
with other models as well:

class Message(models.Model):
    type = models.IntegerField(default=MessageType.INTERNAL, 
choices=MessageType)
    subject = models.CharField(max_length=128, verbose_name=__("Subject"))
    body = models.TextField(verbose_name='')
    sender = models.ForeignKey(User, editable=False, null=True,
                               related_name='ge_message')
    sms_from = models.CharField(max_length=11, null=True, editable=False)
    created = models.DateTimeField(auto_now_add=True, editable=False)
    flag = models.CharField(max_length=1, editable=False, default=flags.CREATED)

    premium_sum = models.PositiveIntegerField(default=0, editable=False, 
blank=True)
    premium_codeword = models.CharField(max_length=32, editable=False, 
blank=True,
                    null=True)

    billable_type = models.ForeignKey(ContentType, null=True, editable=False)
    billable_id = models.IntegerField(null=True, editable=False)
    billable = generic.GenericForeignKey('billable_type', 'billable_id')


And the environment is: Django 1.3, Python 2.4.3 (RHEL 5), Postgres 8.1, using
the postgresql_psycopg2 backend.


-- 
mvh Jens Ådne Rydland

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to