﻿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
8990	Cannot save objects when using extra() in default manager	miracle2k	Malcolm Tredinnick	"Possibly related to #5768 and #3358 (FIXME: select_related isn't supported in values() comment in source).

The last test should not throw an exception:

{{{
from django.db import models

class Shelf(models.Model):
    name = models.CharField(max_length=50)

    def __unicode__(self):
        return u""%s the shelf"" % self.name


class BookManager(models.Manager):
    def get_query_set(self):
        return super(BookManager, self).get_query_set().\
            select_related('shelf').\
            extra(select={'shelf_name': 'extra_save_shelf.name'})


class Book(models.Model):
    name = models.CharField(max_length=50)
    shelf = models.ForeignKey(Shelf)

    objects = BookManager()

    def __unicode__(self):
        return u""%s the book"" % self.name


__test__ = {'API_TESTS':""""""
>>> shelf = Shelf(name=""Foo"")
>>> shelf.save()
>>> book = Book(name=""bar"", shelf=shelf)
>>> book.save()              # initial save works fine

>>> Book.objects.get(pk=1)   # querying works as well
<Book: bar the book>

# subsequent saves fail due to missing select_related
>>> book.save()
Traceback (most recent call last):
    ...
OperationalError: no such column: extra_save_shelf.name
""""""
}
}}}

The problem seems to be that the .extra().values() query that is used to determine whether to do an update or insert doesn't use select_related(), while the manager's extra clause() relies on the tables from select_related existing.

Is there a reason why save's extra() query would need to consider the manager's at all? Wouldn't overwriting existing extra()s be the right thing to do in any case?"		closed	Database layer (models, ORM)	dev		fixed			Accepted	1	0	0	0	0	0
