﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12501	Inconsistent behaviour in querying and creating objects	DmitryRisenberg	nobody	"I have a strange behaviour for the following models:


{{{
from django.db import models

class Channel(models.Model):
    def createSubscription(self):
        subscription = Subscription.objects.create(channel = self)
        print Subscription.objects.filter(channel = self)
        return subscription

class FeedChannel(Channel):
    link = models.CharField(max_length = 200, primary_key = True)

class Subscription(models.Model):
    channel = models.ForeignKey(Channel)
}}}

This is what I get when I run ./manage.py shell with a newly created DB:

{{{
>>> from smth import models
>>> c = models.FeedChannel.objects.create()
>>> s = c.createSubscription()
[]
>>> print s.channel.id, c.channel_ptr.id
1 1
>>>
>>>
}}}

The {{{filter}}} query in {{{createSubscription}}} does not include the created object. I either expect the {{{filter}}} query to select the newly created {{{Subscription}}} object, because its {{{channel}}} field points to the correct {{{Channel}}} instance, or the {{{create}}} query to fail when it encounters an object of derived type instead of base.

Without the {{{primary_key}}} constraint on {{{link}}} field everything works just as expected.

I am using Django 1.1 and Python 2.5."	Bug	closed	Database layer (models, ORM)	1.1	Normal	fixed		commando@…	Accepted	0	0	0	0	0	0
