Opened 10 years ago

Closed 10 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

Description

Hi.
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'

Product.objects.selected_related('current_product').all()

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

Download all attachments as: .zip

Change History (9)

comment:1 by Tim Graham, 10 years ago

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?

by Tim Graham, 10 years ago

Attachment: 21848-test.diff added

comment:2 by Anssi Kääriäinen, 10 years ago

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.

by anonymous, 10 years ago

Attachment: bug_reproduce.tar.gz added

comment:3 by anonymous, 10 years ago

Hi.
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:
http://gyazo.com/782dbfc4fb34a362021cba5ca0095448
http://gyazo.com/e2f475a6547a29389a2b250113a31b7c

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

comment:4 by anonymous, 10 years ago

Why did you close this bug?

comment:5 by anonymous, 10 years ago

I've used
MySQL-python==1.2.5
Django 1.6.1

comment:6 by Anssi Kääriäinen, 10 years ago

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

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