﻿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
17143	select_related makes base __init__ unsafe	Leo Shklovskii		"For the following models setup:

{{{#!python
class A(models.Model):
    foo = models.CharField(max_length=1, default='N')
    
    def __init__(self, *args, **kwargs):
        super(A, self).__init__(*args, **kwargs)
        
        print self.foo
    
class B(A):
    bar = models.CharField(max_length=1, default='X')
}}}

The `print` in in class `A` is just a proxy for doing something else with the field. My specific use case is that I'm trying to save the field off so I can detect whether it has been changed on save or not - but that doesn't impact the bug.

{{{#!python
>>> b = B(foo='Y', bar='Z')
Y
>>> b.save()
>>> A.objects.select_related('b')
Y
N
[<A: A object>]
}}}

The second call to `A.__init__` is to create the B object, however, it doesn't have all of the fields from the original A so while in `A.__init__`, `self.foo` evaluates to the wrong value.

This is either something broken with what fields `select_related` loads on related objects, or it needs to be documented as a really really nasty gotcha for inherited classes/`select_related`."	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	0	0	0	0	0	0
