#21848 closed Bug (fixed)

Some strange problem in Model inheritance and selected_related

Reported by: davydov.ilya@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords: model, inheritance, selected_related
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I've found some strange problem.
I have 2 models.

class Product(models.Model):

id = models.AutoField(primary_key=True)
price = models.IntegerField(db_column='price', default=0)

class Meta:

db_table = 'product'

class CurrentProduct(Product):

parent_product = models.OneToOneField(Product, parent_link=True, related_name='current_product', db_column='parent')
price_test = models.IntegerField(default=0, db_column='price_frame')

class Meta:

db_table = 'door'


The above query return all products. But price_test in subobjects current_product will be casted to:
1) if price_test >= 2 - long
2) if price_test == 1 or price_test == 0 - bool !!!!!!!!!!

It's very strange.

It doesn't repeat if selected_related isn't specified!

What do you mean about it?

Attachments (2)

21848-test.diff (1.6 KB) - added by timo 21 months ago.
bug_reproduce.tar.gz (9.5 KB) - added by anonymous 21 months ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 21 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I wrote a test for Django's test suite based on your description, but I can't reproduce the problem. Can you provide more details and/or tell me if my test isn't correct for the problem you're seeing?

Changed 21 months ago by timo

comment:2 Changed 21 months ago by akaariai

The value conversion has changed a lot in recent versions. In addition value conversion is DB backend specific.

To triage this ticket we need information of used Django version and which backend is in use.

Changed 21 months ago by anonymous

comment:3 Changed 21 months ago by anonymous

I've written small apllication that reproduce this situation. I've attached it to ticket.
I use: DB Mysql and Django 1.6.1

Please, look at next screenshots:

If you need more information, could you contact me by email: davydov.ilya@…?

comment:4 Changed 20 months ago by anonymous

Why did you close this bug?

comment:5 Changed 20 months ago by anonymous

I've used
Django 1.6.1

comment:6 Changed 20 months ago by akaariai

Hmmh... maybe this too will be fixed by 9918c11114ac3ec9622631558ef26ebf3919cb69 (see tickets #21903, #21413). I can't verify that right now. Trying that https://github.com/akaariai/django/commit/e9a48efe366f1fab7e888cd9648ba69a06bece4a fixes the issue would be very helpful.

comment:7 Changed 20 months ago by anonymous

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

You've fixed this problem in release 1.6.2! Thank you!

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