﻿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
28787	QuerySet.update() fails on MySQL if a subquery references the base table	Paulo	nobody	"Given the models below:


{{{
class House(models.Model):
    name = models.CharField(max_length=200)

class Room(models.Model):
    name = models.CharField(max_length=200)
    house = models.ForeignKey(House, on_delete=models.CASCADE)
}}}


The following query fails:


{{{
houses_with_suites = House.objects.filter(room__name__icontains='suite')
Room.objects.filter(house__in=houses_with_suites).update(name='suite')
}}}

With this error:


{{{
OperationalError: (1093, ""You can't specify target table 'mysql_test_room' for update in FROM clause"")
}}}

I think this has been around for a while (#20300).

I've confirmed this only happens in MySQL. It works on PostgresSQL and SQLite."	Bug	closed	Database layer (models, ORM)	1.11	Normal	invalid		Mariusz Felisiak	Accepted	0	0	0	0	0	0
