Opened 4 years ago

Closed 4 years ago

#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 Tim Graham 4 years ago.
bug_reproduce.tar.gz (9.5 KB) - added by anonymous 4 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 4 years ago by Tim Graham

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 4 years ago by Tim Graham

Attachment: 21848-test.diff added

comment:2 Changed 4 years ago by Anssi Kääriäinen

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 4 years ago by anonymous

Attachment: bug_reproduce.tar.gz added

comment:3 Changed 4 years 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 4 years ago by anonymous

Why did you close this bug?

comment:5 Changed 4 years ago by anonymous

I've used
Django 1.6.1

comment:6 Changed 4 years ago by Anssi Kääriäinen

Hmmh... maybe this too will be fixed by 9918c11114ac3ec9622631558ef26ebf3919cb69 (see tickets #21903, #21413). I can't verify that right now. Trying that fixes the issue would be very helpful.

comment:7 Changed 4 years ago by anonymous

Resolution: fixed
Status: newclosed

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

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