Opened 5 years ago

Closed 21 months ago

#12501 closed Bug (fixed)

Inconsistent behaviour in querying and creating objects

Reported by: DmitryRisenberg Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Normal Keywords:
Cc: commando@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (5)

comment:1 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

By putting the primary_key flag on the link, channel=self is no longer able to roll out as channel=self.pk. Some additional checks will be required internally to make sure the right parent link/value is used.

comment:2 Changed 4 years ago by mattmcc

  • Severity set to Normal
  • Type set to Bug

comment:3 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 21 months ago by akaariai

  • Resolution set to fixed
  • Status changed from new to closed

This seems to be fixed in master. I am somewhat confident that this one has been tested already so I won't add more tests for this).

Note: See TracTickets for help on using tickets.
Back to Top